HTTP Long Polling

I want to read about HTTP long polling because it is a concept important in the use of Socket.io.

Date Created:
0 21

References



Notes


Long Polling is a backend technique used in web development and networking to emulate real-time communication between a client (usually a web browser) and a server. Long polling is used in real-time web apps.

Long polling improves communication efficient by keeping the request open for an extended period until new data is available. The server holds the request open and waits until it has new information to send back to the client. Once the server has new data, it responds to the client, which can then process the data and initiate a new long polling request.

By maintaining a long-lived connection between the client and server, long polling reduces the total number of requests. This makes it a good tech stack for building scalable, responsive chat apps, multiplayer games, live notifications, and industrial and automotive solutions.

Long polling is a push-based approach that allows the server to send updates to the client as soon as they are available, eliminating need for the client to check for updates repeatedly.

Long Polling Process Workflow:

  1. The client initiates a request to the server, typically through an HTTP request
  2. Instead of immediately responding, the server holds the request open, keeping the connection active
  3. If no new data is available, the server waits until it has something to send back
  4. Once the server has new data or a predefined timeout occurs, it responds to the client with the latest information
  5. Upon receiving the response, the client immediately sends another request to the server to maintain the connection.
  6. This cycle of sending requests and receiving responses continues, ensuring real-time updates.

In traditional HTTP, the client sends a request to the server and waits for a response, known as short polling. This method is inefficient for real-time scenarios due to frequent requests causing network overhead and increased latency. Short polling, a pull-based approach, results in delays as the client repeatedly checks for updates.

HTTP long polling is a widely used long polling approach that leverages HTTP to maintain a long-lived client-server connection. The client sends a request, which the server holds open until new data is available or a timeout occurs. Once the server responds, the client immediately sends another request, continuing the cycle. This method is simple to implement.

Comments

You have to be logged in to add a comment

User Comments

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Lexical State

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload 3D Object

ESC

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image Background Color

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language

Insert Chart

ESC

Use the search box below

Upload Previous Version of Article State

ESC