software development

WebSockets Tutorial


WebSocket is standard protocol that is able to provide persistent connection between a server and a client. WebSockets are bidirectional, which means a server and client and send and receive data in the same channel, full-duplex communication protocol that is implemented on TCP/IP socket.

WebSockets were built to counter the limits of HTTP protocol.

First, in HTTP protocol, is not bidirectional. The client requests a specific resource on the server, once the server finds and sends the resource to the client, the connection is closed. This means that for a very active data flow, such as streaming service, there will be too much requests on the server.

Unlike HTTP, WebSockets are able to maintain a connection until either the client or the server terminates it. It works by first creating a handshake between the client and the server, then followed by an UPGRADE header. Once established, a flow of data between the server and the client is also established.

The above diagram illustrates how HTTP protocol works compared to WebSockets.

NOTE: The diagrams above do not give a full-fledged working of either HTTP or WebSocket protocols.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list