What is WebSocket?

Ayberk Gerey
2 min readJan 19, 2024

--

WebSocket is a communication protocol which provides full duplex communication channels over single TCP connections. It’s designed to be implemented in web browsers and web servers, but also It can be used by any client or server applications.

Unlike the traditional HTTP protocol, with WebSockets a continuous connection can be established and data is transmitted over this connection in real time. This is the ideal solution for instantaneous and interactive data transfer between applications.

So WebSockets provides a persistence connection between the client and the server. Both parties can start sending data anytime. WebSockets is a powerful tool for delivering real-time and interactive content in web applications.

Advantages

  • Realtime Data Transfer

WebSockets are capable of realtime data exchange on websites or on apps. It provide real-time data transmission without delay. So it makes easier to develop live chat apps, stock tracking systems, real-time data monitoring and updating applications.

  • Bi-Directional

It refers to a situation where a bi-directional connection is established between both the server and the client, and both sides have the ability to send and receive data.

  • Efficient

Like Http protocol the WebSocket doesn’t require headers to send any message thus resulting in less data transfer.

  • Persistent Connection

Also, since the connection “between server and the client” remains open, there is no need to establish connections again and again to constantly exchange data.

Main Difference between Http and WebSocket protocols.

WebSocket is a communication protocol that supports two-way communication, but Http is generally used for one-way data transmission.

Handshake

When WebSocket is used, the client starts with an HTTP request. However, this request points to a path and is then elevated to initiate a WebSocket connection. This process is called “handshake” and both parties get to know each other and become available for real-time communication.

Thank you for reading, Cheers!

--

--

Ayberk Gerey
Ayberk Gerey

No responses yet