Introduction to HTTP and Websockets
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.
1 In this way , request-response is held between the client and server.
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.