Introduction to HTTP and Websockets

1 Min. Read
Dec 8, 2019


HTTP stands for Hypertext Transfer Protocol which is the most common term used in the web technology. It is the protocol used for transferring the files such as text, graphic, images, and other multimedia files on the web. It works on the basis of request-response protocol between client and server. HTTP client sends a request message to an HTTP server, then the server returns a response message. It is stateless, which means that the each request sent to a server is independent of the other requests. By default, HTTP uses port 80 and HTTPS uses port 443.

When the URL is entered in the browser, the entered URL gets translated to it respective IP address from the DNS and the browser sends the request to the server according to the specified protocol. After the message reaches the server,

1 The server maps the requested resources to it’s directory and returns the file as the request to the client. If it doesn’t contains the requested file it redirects the request to the other server which is known as the proxy. If the file is not contain in any of the server it returns an error message.

2 The browser receives the response message, it first parse the html document and on the basis of it creates the DOM. As traversing through the DOM, each element is generated. In case of the assets link of the sites, the browser sends the request to the server, in return the server again response with the required responses.

In this way , request-response is held between the client and server.

HTTP Polling

It is a technique where the server holds the client’s request open until new data is available, upon finding the new information, the server responds with the updated information to the client. One of it’s applicable example would be a chatting system. Without the http polling, if one client sends message to other client, the message wouldn’t be displayed to the other client until he/she refreshes the browser (sends requests). Upon using polling which ultimately happens from the javascript, the changes (new information) in the server is automatically get in the client browser. However, the process is unidirectional.


WebSockets are the alternative to the HTTP communication which allows bidirectional protocol, which means client and server can send a message to each other independently at the same time by crating a persistent between the two. For this a normal HTTP request is upgraded with a special header, both the server and the client agrees to upgrade the connection which becomes a WebSocket connection also known as a handshake. It is useful for the service that require continuous data exchange such as chatting, online games and so on.