kdastate.blogg.se

Node js websocket example
Node js websocket example







node js websocket example

The protocol is not raw TCP because it needs to provide the browser's "same-origin" security model. In addition to the new WebSocket API, there is also a new protocol (the "WebSocket Protocol") that the browser uses to communicate with servers. Once you get a WebSocket connection, you can send data from browser to server by calling a send() method, and receive data from server to browser by an onmessage event handler. As opposed to XMLHttpRequest, WebSockets provide a real bidirectional communication channel in your browser. XHR is basically asynchronous HTTP, and because you need to use a tricky technique like long-hanging GET for sending data from the server to the browser, simple tasks rapidly become complex. Developers have been using XMLHttpRequest ("XHR") for such purposes, but XHR makes developing web applications that communicate back and forth to the server unnecessarily complex. The WebSocket API enables web applications to handle bidirectional communications with server-side process in a straightforward way. When Google announced the availability of WebSocket in Google Chrome, it explained the idea behind WebSockets: It defines an interoperable wire format so that any of the available STOMP clients can communicate with any STOMP message broker to provide easy and widespread messaging interoperability among languages and platforms (the STOMP web site has a list of STOMP client and server implementations.

node js websocket example

STOMP is a simple text-orientated messaging protocol.









Node js websocket example