Showing posts from December, 2022

HTTP Long Polling vs WebSockets

In a typical client to server model, to communicate with server, client opens a HTTP connection and sends the request over that connection to the server. Server process the request and sends the response back to the client. After that connection is closed. Next time client needs to communicate to the server, client will open a new HTTP connection with the server. In applications, where client needs to repeatedly talk to server for updates in very small intervals of time, this can waste lot of resources. For example, In chat applications client will periodically poll the server in very small intervals of time for the new messages, server might not have new messages all the time. This can lead to wastage of compute resources. We need ways to reduce the number of connections created between client and server. To solve the above problem, there are two most popular solutions. 1. HTTP Long Polling 2. Websockets. HTTP Long Polling In HTTP Long polling, server holds the connection as long as i