Learn websocket basics - Comparison with Http protocal

Web socket beginner tutorials 

WebSocket is a protocol with two way HTTP connection between client and server. Communication happened over a single socket layer,

Traditional client-server communication web applications

Normal Web applications, the client initiates the request and server serve the response. Here communication is over HTTP protocol, Once the content is served on the page, no updated content will be served until the page is refreshed.

 Think of following use cases where real-time communication required in Facebook Chat, Live Cricket scores, Stock Quotes News feed Online games Real-time applications communications For example, Now think of live Cricket based score websites/ Facebook chat sites, the data displayed on live cricket score is very frequent. The live score once displayed might be outdated. Continues refresh is required to get the newly updated score. This might be a poor user experience For real-time web apps communication, Traditional client-server communication is not used as this has a poor user experience.

Solutions to this problem are having two options
1.Polling
2.Long Polling

Polling- alternative to WebSocket

1. The client sends a request to the server, HTTP connection is opened
2. The server serves the response over HTTP connection and server closes this connection
3. step1 and step2 happen at frequent intervals for getting update content at frequent intervals for every request, HTTP connection is created Once data served, the connection will be closed.

Polling disadvantages

1. More bandwidth is required if there is no content update
2. Connection open/close is an expensive operation for every request during interval time.

Long polling alternative to WebSocket 

1. This method is asynchronous polling
2. The server keeps the connection open until the configured period timeout is reached

Advantages 

When data is huge, it becomes polling.

Http

Websockets

Oneway communication - Client sends a request to the server, the server sends the responses

Two-way communication ie duplex channel

The server can not push to client

Core feature and Server push is possible

Cache inbuilt support

Cache is not possible

All clients and browsers support there

Only Modern browsers supports

All technologies support available

Only Modern languages support available

WebSocket support in all popular browsers. Following libraries have support for implementing WebSocket implementation

sockJS

Socket.io

Similar Posts