Web Sockets Vs. HTTP

Matt Sewell
2 min readAug 9, 2021

What are WebSockets and how do they differ from HTTP? What is HTTP? How are WebSockets used and what are some use cases? Below is an overview of Web Sockets and HTTP.

The Hypertext Transfer Protocol, or HTTP, is a unidirectional protocol where the client sends a request to a server and the server sends a response. When the client sends the request, a connection between the client and the server is opened. When the request is received, the server then sends the response back to the client, and the connection is terminated. Each request/response opens a different connection to the server, so each time a client sends a request, a new connection is opened and closed. The url for HTTP requests begins with http:// or https://.

WebSockets are a bidirectional protocol where a connection is established between the client and the server, remaining open until the connection is terminated by either the client or the server. First, a request for a connection is made by the client to the server, then the server accepts the request with a handshake, which opens the WebSocket connection. Once the connection is open, information can flow from the server to the client or vice versa in real time. When either side decides to terminate the connection, it is closed. The url for WebSockets begins with ws:// or wss://.

The main reason to use WebSockets is for data that is changing in real time. Examples of this include: instant messaging, stock tickers, and notification services.

It is sufficient to use HTTP for data that needs to be fetched infrequently or only once. WebSockets are used to fetch frequently updated data where it is necessary to have immediate updates to the information served to the client side.

--

--