Skip to contentমূল লেখায় যান

Topic 39 · Courseটপিক 39 · Course

Long Polling, WebSockets, and SSE

A chat page must show a new message the moment it arrives. But a browser normally asks, and the server answers. So how can the server speak first? This page compares three answers: long polling, WebSockets, and server-sent events (SSE).

7 min read7 মিনিটে পড়া যায় · 9 sections9টি সেকশন · 5 sources5টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Three ways to push eventsইভেন্ট পুশ করার তিনটি উপায়

Run the same events through long polling, SSE and a WebSocket, and count the requests each one needs.একই ইভেন্টগুলো long polling, SSE আর WebSocket দিয়ে চালান, আর প্রতিটির অনুরোধ গুনুন।

2 min2 মিনিট7 steps7টি ধাপ
  • Long polling requestsলং পোলিং অনুরোধ1
  • SSE requestsSSE অনুরোধ0
  • WebSocket requestsWebSocket অনুরোধ0
Long pollingলং পোলিংSSE · one-waySSE · একমুখীWebSocket · two-wayWebSocket · দ্বিমুখী1 request, held1টি অনুরোধ, ধরাyou · clientআপনি · ক্লায়েন্টServerসার্ভারholds the requestঅনুরোধ ধরে রাখে

You’ll learnআপনি শিখবেন

  • Why long polling sends a new request per eventLong polling কেন প্রতি ইভেন্টে নতুন অনুরোধ পাঠায়
  • How SSE keeps one open, one-way streamSSE কীভাবে একটি খোলা একমুখী স্ট্রিম রাখে
  • How a WebSocket upgrades and sends both waysWebSocket কীভাবে আপগ্রেড হয় আর দুই দিকে পাঠায়
  • Why reconnects need a random, growing delayরিকানেক্টে কেন র‍্যান্ডম, বাড়তে থাকা বিরতি লাগে

In plain words

In plain HTTP, a client sends a request and the server sends one response. A server cannot open a connection to the client, and it cannot send a response that nobody asked for Source 1সোর্স 1. A client can ask again and again (polling). This wastes bandwidth when nothing is new, and data waits until the next poll Source 1সোর্স 1.

The three techniques below let the server send data sooner. They differ in the direction of data and in how they recover from a broken connection.

সহজ English

In plain HTTP, a client sends a request and the server sends one response. A server cannot open a connection to the client. It cannot send a response that nobody asked for Source 1সোর্স 1. A client can ask again and again. This is polling. It wastes bandwidth when nothing is new, and data waits until the next poll Source 1সোর্স 1.

Three techniques let the server send data sooner. They differ in the direction of data. They also differ in how they recover from a broken connection.

বাংলা ব্যাখ্যা

সাধারণ HTTP-তে একটি ক্লায়েন্ট রিকুয়েস্ট পাঠায় আর সার্ভার একটি রেসপন্স পাঠায়। সার্ভার ক্লায়েন্টের দিকে কানেকশন খুলতে পারে না। কেউ চায়নি এমন রেসপন্সও সে পাঠাতে পারে না Source 1সোর্স 1। ক্লায়েন্ট বারবার জিজ্ঞেস করতে পারে। একে পোলিং (polling) বলে। নতুন কিছু না থাকলে এতে ব্যান্ডউইথ নষ্ট হয়, আর ডেটা পরের পোল পর্যন্ত অপেক্ষা করে Source 1সোর্স 1।

তিনটি টেকনিক সার্ভারকে আগে ডেটা পাঠাতে দেয়। এগুলো ডেটার দিকে আলাদা। ভাঙা কানেকশন থেকে ফিরে আসার উপায়েও এগুলো আলাদা।

How it works

Long polling

The server holds a request open. It answers only when there is an event, a status change, or a timeout Source 1সোর্স 1. Then the client usually sends a new request at once, or after a short pause Source 1সোর্স 1. Data pushes from server to client. Upstream data goes as separate HTTP calls Source 2সোর্স 2. Each request and each response is a complete HTTP message with its own headers Source 1সোর্স 1.

WebSockets

A WebSocket starts as an HTTP request with an Upgrade: websocket header. If the server agrees, it answers with status 101 Switching Protocols Source 2সোর্স 2. After that, both sides can send data at any time, on the same connection Source 2সোর্স 2. Data travels in messages, and a message is made of one or more frames. A frame can hold text (UTF-8), binary data, or a control signal such as Close, Ping, or Pong Source 2সোর্স 2. A Ping can serve as a keepalive Source 2সোর্স 2. The RFC says implementations must support TLS (wss URLs) and should use it Source 2সোর্স 2.

MDN warns that the WebSocket interface has no backpressure. If messages arrive faster than the app can handle them, the memory may fill, the CPU may reach 100%, or both Source 4সোর্স 4.

Reconnection. After an abnormal closure, a client should wait before it reconnects. The RFC says the first attempt should follow a random delay (0 to 5 seconds is given as a reasonable start). Later attempts should wait longer each time, for example with truncated binary exponential backoff Source 2সোর্স 2. Many clients that reconnect at once may act like a denial-of-service attack Source 2সোর্স 2. The sources on this page describe no built-in way to get messages sent while the client was offline. This is the tutorial's own note: the app must design that part.

Server-sent events (SSE)

The page creates an EventSource with a URL. The server answers with the MIME type text/event-stream Source 5সোর্স 5. The stream is UTF-8 text Source 3সোর্স 3. Each message is a block of lines such as data: hello, and a blank line ends the block Source 5সোর্স 5. The fields are event, data, id, and retry Source 3সোর্স 3. SSE is a one-way connection: the client cannot send events to the server Source 5সোর্স 5.

Reconnection. By default, the browser restarts the connection when it closes Source 5সোর্স 5. Before it retries, it waits for the reconnection time. The first value depends on the browser, and the standard says it is probably a few seconds Source 3সোর্স 3. The retry field sets this time in milliseconds Source 5সোর্স 5. The id field sets the last event ID. On reconnection, the browser sends that ID in the Last-Event-ID request header Source 3সোর্স 3. What the server then sends is up to the server. This is the tutorial's own note.

Two ways to stop the reconnection: the server answers with 204 No Content Source 3সোর্স 3, or the client calls close() Source 5সোর্স 5. If the response status is not 200, or the content type is not text/event-stream, the browser fails the connection and does not reconnect Source 3সোর্স 3.

সহজ English

Long polling. The server holds a request open. It answers only when there is an event, a status change, or a timeout Source 1সোর্স 1. Then the client usually sends a new request at once, or after a short pause Source 1সোর্স 1. Data pushes from server to client. Upstream data goes as separate HTTP calls Source 2সোর্স 2. Each request and each response is a complete HTTP message with its own headers Source 1সোর্স 1.

WebSockets. A WebSocket starts as an HTTP request with an Upgrade: websocket header. If the server agrees, it answers with status 101 Switching Protocols Source 2সোর্স 2. After that, both sides can send data at any time, on the same connection Source 2সোর্স 2. Data travels in messages, and a message is made of one or more frames. A frame can hold text (UTF-8), binary data, or a control signal such as Close, Ping, or Pong Source 2সোর্স 2. A Ping can serve as a keepalive Source 2সোর্স 2. The RFC says implementations must support TLS (wss URLs) and should use it Source 2সোর্স 2.

MDN warns that the WebSocket interface has no backpressure. Suppose messages arrive faster than the app can handle them. Then the memory may fill, the CPU may reach 100%, or both Source 4সোর্স 4.

Reconnection for WebSockets: After an abnormal closure, a client should wait before it reconnects. The RFC says the first attempt should follow a random delay (0 to 5 seconds is given as a reasonable start). Later attempts should wait longer each time, for example with truncated binary exponential backoff Source 2সোর্স 2. Many clients that reconnect at once may act like a denial-of-service attack Source 2সোর্স 2. The sources on this page describe no built-in way to get messages sent while the client was offline. This is the tutorial's own note: the app must design that part.

Server-sent events (SSE). The page creates an EventSource with a URL. The server answers with the MIME type text/event-stream Source 5সোর্স 5. The stream is UTF-8 text Source 3সোর্স 3. Each message is a block of lines such as data: hello, and a blank line ends the block Source 5সোর্স 5. The fields are event, data, id, and retry Source 3সোর্স 3. SSE is a one-way connection. The client cannot send events to the server Source 5সোর্স 5.

Reconnection for SSE: By default, the browser restarts the connection when it closes Source 5সোর্স 5. Before it retries, it waits for the reconnection time. The first value depends on the browser. The standard says it is probably a few seconds Source 3সোর্স 3. The retry field sets this time in milliseconds Source 5সোর্স 5. The id field sets the last event ID. On reconnection, the browser sends that ID in the Last-Event-ID request header Source 3সোর্স 3. What the server then sends is up to the server. This is the tutorial's own note.

Two things stop the reconnection. The server answers with 204 No Content Source 3সোর্স 3, or the client calls close() Source 5সোর্স 5. If the response status is not 200, or the content type is not text/event-stream, the browser fails the connection and does not reconnect Source 3সোর্স 3.

বাংলা ব্যাখ্যা

Long polling। সার্ভার একটি রিকুয়েস্ট খোলা ধরে রাখে। সে শুধু তখনই উত্তর দেয়, যখন একটি ইভেন্ট, স্ট্যাটাসের পরিবর্তন বা একটি টাইমআউট থাকে Source 1সোর্স 1। তারপর ক্লায়েন্ট সাধারণত সাথে সাথে, বা অল্প বিরতির পরে, একটি নতুন রিকুয়েস্ট পাঠায় Source 1সোর্স 1। ডেটা সার্ভার থেকে ক্লায়েন্টের দিকে পুশ হয়। উল্টো দিকের ডেটা আলাদা HTTP কলে যায় Source 2সোর্স 2। প্রতিটি রিকুয়েস্ট ও প্রতিটি রেসপন্স নিজস্ব হেডার সহ একটি সম্পূর্ণ HTTP মেসেজ Source 1সোর্স 1।

WebSockets। WebSocket শুরু হয় Upgrade: websocket হেডার সহ একটি HTTP রিকুয়েস্ট হিসেবে। সার্ভার রাজি হলে সে 101 Switching Protocols স্ট্যাটাস দিয়ে উত্তর দেয় Source 2সোর্স 2। এরপর দুই পক্ষই একই কানেকশনে যেকোনো সময় ডেটা পাঠাতে পারে Source 2সোর্স 2। ডেটা মেসেজ হিসেবে চলে, আর একটি মেসেজ এক বা একাধিক ফ্রেম (frame) দিয়ে তৈরি। একটি ফ্রেমে টেক্সট (UTF-8), বাইনারি ডেটা, বা Close, Ping ও Pong-এর মতো একটি কন্ট্রোল সিগন্যাল থাকতে পারে Source 2সোর্স 2। একটি Ping কিপঅ্যালাইভ (keepalive) হিসেবে কাজ করতে পারে Source 2সোর্স 2। RFC বলে, ইমপ্লিমেন্টেশনকে অবশ্যই TLS (wss URL) সাপোর্ট করতে হবে এবং TLS ব্যবহার করা উচিত Source 2সোর্স 2।

MDN সতর্ক করে যে WebSocket ইন্টারফেসে ব্যাকপ্রেশার (backpressure) নেই। ধরুন মেসেজ অ্যাপের সামলানোর চেয়ে দ্রুত আসছে। তখন মেমরি ভরে যেতে পারে, CPU 100%-এ পৌঁছাতে পারে, বা দুটিই হতে পারে Source 4সোর্স 4।

WebSocket-এর রিকানেকশন: অস্বাভাবিকভাবে বন্ধ হওয়ার পর একটি ক্লায়েন্টের রিকানেক্ট করার আগে অপেক্ষা করা উচিত। RFC বলে, প্রথম চেষ্টা একটি র‍্যান্ডম বিরতির (delay) পরে হওয়া উচিত (একটি যুক্তিসঙ্গত শুরু হিসেবে 0 থেকে 5 সেকেন্ড বলা হয়েছে)। পরের চেষ্টাগুলোতে প্রতিবার আরও বেশি অপেক্ষা করা উচিত, যেমন truncated binary exponential backoff দিয়ে Source 2সোর্স 2। অনেক ক্লায়েন্ট একসাথে রিকানেক্ট করলে তা ডিনায়াল-অফ-সার্ভিস (denial-of-service) অ্যাটাকের মতো কাজ করতে পারে Source 2সোর্স 2। এই পেজের সোর্সগুলো এমন কোনো বিল্ট-ইন উপায় বর্ণনা করে না, যা দিয়ে ক্লায়েন্ট অফলাইন থাকার সময় পাঠানো মেসেজ পাওয়া যায়। এটি টিউটোরিয়ালের নিজস্ব মন্তব্য: অ্যাপকে সেই অংশটি ডিজাইন করতে হবে।

Server-sent events (SSE)। পেজ একটি URL দিয়ে একটি EventSource তৈরি করে। সার্ভার MIME টাইপ text/event-stream দিয়ে উত্তর দেয় Source 5সোর্স 5। স্ট্রিম হলো UTF-8 টেক্সট Source 3সোর্স 3। প্রতিটি মেসেজ হলো data: hello-এর মতো কয়েকটি লাইনের একটি ব্লক, আর একটি ফাঁকা লাইন ব্লক শেষ করে Source 5সোর্স 5। ফিল্ডগুলো হলো event, data, id ও retry Source 3সোর্স 3। SSE একমুখী কানেকশন। ক্লায়েন্ট সার্ভারকে ইভেন্ট পাঠাতে পারে না Source 5সোর্স 5।

SSE-র রিকানেকশন: ডিফল্ট হিসেবে কানেকশন বন্ধ হলে ব্রাউজার সেটি আবার শুরু করে Source 5সোর্স 5। আবার চেষ্টা করার আগে সে রিকানেকশন টাইম পর্যন্ত অপেক্ষা করে। প্রথম মান ব্রাউজারের ওপর নির্ভর করে, আর স্ট্যান্ডার্ড বলে এটি সম্ভবত কয়েক সেকেন্ড Source 3সোর্স 3। retry ফিল্ড এই সময় মিলিসেকেন্ডে ঠিক করে Source 5সোর্স 5। id ফিল্ড শেষ ইভেন্ট ID ঠিক করে। রিকানেকশনের সময় ব্রাউজার সেই ID Last-Event-ID রিকুয়েস্ট হেডারে পাঠায় Source 3সোর্স 3। তখন সার্ভার কী পাঠাবে তা সার্ভারের ওপর নির্ভর করে। এটি টিউটোরিয়ালের নিজস্ব মন্তব্য।

দুটি জিনিস রিকানেকশন থামায়। সার্ভার 204 No Content দিয়ে উত্তর দেয় Source 3সোর্স 3, অথবা ক্লায়েন্ট close() কল করে Source 5সোর্স 5। রেসপন্স স্ট্যাটাস 200 না হলে, বা কনটেন্ট টাইপ text/event-stream না হলে, ব্রাউজার কানেকশন ফেইল করে এবং রিকানেক্ট করে না Source 3সোর্স 3।

When you need it

This is the tutorial's own advice. Use one of these when the server must tell the client about a change at once: a chat, a live score, or a progress bar. Ask first which way data must flow. If only the server sends, SSE or long polling may be enough. If both sides send often, a WebSocket fits.

সহজ English

This is the tutorial's own advice. Use one of these when the server must tell the client about a change at once. Examples are a chat, a live score, or a progress bar. Ask first which way data must flow. If only the server sends, SSE or long polling may be enough. If both sides send often, a WebSocket fits.

বাংলা ব্যাখ্যা

এটি টিউটোরিয়ালের নিজস্ব পরামর্শ। সার্ভারকে যখন কোনো পরিবর্তনের কথা ক্লায়েন্টকে সাথে সাথে জানাতে হয়, তখন এর একটি ব্যবহার করুন। যেমন চ্যাট, লাইভ স্কোর বা প্রগ্রেস বার। প্রথমে জিজ্ঞেস করুন ডেটা কোন দিকে চলবে। শুধু সার্ভার পাঠালে SSE বা long polling যথেষ্ট হতে পারে। দুই পক্ষ প্রায়ই পাঠালে WebSocket মানায়।

Issues that RFC 6202 lists

RFC 6202 says that HTTP was not designed for two-way communication. It neither encourages nor discourages these techniques, and it lists their issues Source 1সোর্স 1. It dates from 2011, so check newer browser details. The main points:

Long polling

  • Header overhead. Every message carries full HTTP headers. For small messages, the headers can be a large part of the data Source 1সোর্স 1.
  • Latency. The average latency is close to one network transit. The worst case is over three, because the server must wait for the next request Source 1সোর্স 1.
  • Held resources. Each client holds a TCP connection and an HTTP request. Some gateways, proxies, and servers can hold only a limited number of requests Source 1সোর্স 1.
  • Timeouts. A high timeout cuts the work, but a value that is too high can bring a 408 Request Timeout or a 504 Gateway Timeout. The RFC says 30 seconds is generally safer Source 1সোর্স 1.
  • Caching. A long poll should suppress caching, with Cache-Control: no-cache Source 1সোর্স 1.

HTTP streaming (SSE sends its events with this technique Source 1সোর্স 1)

Security. Many open connections can make a denial-of-service attack easier Source 1সোর্স 1.

সহজ English

RFC 6202 says that HTTP was not designed for two-way communication. It neither encourages nor discourages these techniques. It lists their issues Source 1সোর্স 1. It dates from 2011, so check newer browser details. These are the main points.

Long polling

  • Header overhead. Every message carries full HTTP headers. For small messages, the headers can be a large part of the data Source 1সোর্স 1.
  • Latency. The average latency is close to one network transit. The worst case is over three, because the server must wait for the next request Source 1সোর্স 1.
  • Held resources. Each client holds a TCP connection and an HTTP request. Some gateways, proxies, and servers can hold only a limited number of requests Source 1সোর্স 1.
  • Timeouts. A high timeout cuts the work. But a value that is too high can bring a 408 Request Timeout or a 504 Gateway Timeout. The RFC says 30 seconds is generally safer Source 1সোর্স 1.
  • Caching. A long poll should suppress caching, with Cache-Control: no-cache Source 1সোর্স 1.

HTTP streaming (SSE sends its events with this technique Source 1সোর্স 1)

Security. Many open connections can make a denial-of-service attack easier Source 1সোর্স 1.

বাংলা ব্যাখ্যা

RFC 6202 বলে, HTTP দ্বিমুখী যোগাযোগের জন্য ডিজাইন করা হয়নি। এটি এই টেকনিকগুলোকে উৎসাহও দেয় না, নিরুৎসাহও করে না। এটি এগুলোর সমস্যা তালিকাভুক্ত করে Source 1সোর্স 1। এটি 2011 সালের, তাই ব্রাউজারের নতুন তথ্য যাচাই করুন। প্রধান পয়েন্টগুলো নিচে দেওয়া হলো।

Long polling

  • হেডার ওভারহেড। প্রতিটি মেসেজ পুরো HTTP হেডার বহন করে। ছোট মেসেজের ক্ষেত্রে হেডার ডেটার একটি বড় অংশ হতে পারে Source 1সোর্স 1।
  • ল্যাটেন্সি। গড় ল্যাটেন্সি এক নেটওয়ার্ক ট্রানজিটের কাছাকাছি। সবচেয়ে খারাপ ক্ষেত্রে তা তিনটির বেশি, কারণ সার্ভারকে পরের রিকুয়েস্টের জন্য অপেক্ষা করতে হয় Source 1সোর্স 1।
  • ধরে রাখা রিসোর্স। প্রতিটি ক্লায়েন্ট একটি TCP কানেকশন আর একটি HTTP রিকুয়েস্ট ধরে রাখে। কিছু গেটওয়ে, প্রক্সি ও সার্ভার সীমিত সংখ্যক রিকুয়েস্টই ধরে রাখতে পারে Source 1সোর্স 1।
  • টাইমআউট। বেশি টাইমআউট কাজ কমায়। কিন্তু খুব বেশি মান 408 Request Timeout বা 504 Gateway Timeout ডেকে আনতে পারে। RFC বলে 30 সেকেন্ড সাধারণত বেশি নিরাপদ Source 1সোর্স 1।
  • ক্যাশিং। একটি long poll-এ Cache-Control: no-cache দিয়ে ক্যাশিং বন্ধ করা উচিত Source 1সোর্স 1।

HTTP streaming (SSE তার ইভেন্ট এই টেকনিক দিয়ে পাঠায় Source 1সোর্স 1)

  • ইন্টারমিডিয়ারি (মাঝখানের অংশ)। একটি প্রক্সি পুরো রেসপন্স বাফার করে তারপর ফরওয়ার্ড করতে পারে। এমন প্রক্সির ভেতর দিয়ে স্ট্রিমিং কাজ করে না Source 1সোর্স 1।
  • ফ্রেমিং। HTTP চাংক একটি মেসেজের শেষ চিহ্নিত করতে পারে না, কারণ প্রক্সি সেগুলো মিলিয়ে দিতে পারে Source 1সোর্স 1।

সিকিউরিটি। অনেক খোলা কানেকশন ডিনায়াল-অফ-সার্ভিস অ্যাটাক সহজ করতে পারে Source 1সোর্স 1।

Trade-offs

Cells with "(tutorial's view)" are the tutorial's own judgment. All other cells follow the sources.

Long pollingWebSocketSSE
DirectionServer pushes through a held request. The client uses ordinary requests to send Source 1সোর্স 1 Source 2সোর্স 2Both ways, on one connection Source 2সোর্স 2Server to client only Source 5সোর্স 5
How it startsAn HTTP request Source 1সোর্স 1An HTTP Upgrade request, then 101 Source 2সোর্স 2An HTTP request, answered with text/event-stream Source 5সোর্স 5
Message formatA complete HTTP message each time Source 1সোর্স 1Frames of text or binary Source 2সোর্স 2UTF-8 text lines Source 3সোর্স 3
ReconnectionThe client sends the next poll Source 1সোর্স 1Client's job. Use backoff Source 2সোর্স 2The browser reconnects. retry and Last-Event-ID help Source 3সোর্স 3
Connection limitBrowser limit on connections applies Source 1সোর্স 1(tutorial's view) The sources on this page give no figureAbout 6 per browser and domain when not on HTTP/2. On HTTP/2 it is negotiated, with a default of 100 Source 5সোর্স 5
ProxiesThey treat a long poll as a normal request. Proxy timeouts can cut it, and caching must be turned off Source 1সোর্স 1The handshake is made to work with HTTP proxies Source 2সোর্স 2Some old proxies drop quiet connections. A comment line about every 15 seconds helps Source 3সোর্স 3
Fits best (tutorial's view)Fallback, or rare updatesChat, games, two-way flowFeeds, notices, progress

সহজ English

Some points are the tutorial's own judgment. They are marked "(tutorial's view)". All other points follow the sources.

Long polling

WebSocket

SSE

বাংলা ব্যাখ্যা

কিছু পয়েন্ট টিউটোরিয়ালের নিজস্ব বিচার। সেগুলোতে "(tutorial's view)" লেখা আছে। বাকি সব পয়েন্ট সোর্স অনুসরণ করে।

Long polling

  • দিক: সার্ভার একটি ধরে রাখা রিকুয়েস্ট দিয়ে পুশ করে। ক্লায়েন্ট পাঠানোর জন্য সাধারণ রিকুয়েস্ট ব্যবহার করে Source 1সোর্স 1 Source 2সোর্স 2।
  • কীভাবে শুরু হয়: একটি HTTP রিকুয়েস্ট দিয়ে Source 1সোর্স 1।
  • মেসেজ ফরম্যাট: প্রতিবার একটি সম্পূর্ণ HTTP মেসেজ Source 1সোর্স 1।
  • রিকানেকশন: ক্লায়েন্ট পরের পোল পাঠায় Source 1সোর্স 1।
  • কানেকশনের সীমা: ব্রাউজারের কানেকশন সীমা প্রযোজ্য Source 1সোর্স 1।
  • প্রক্সি: এগুলো লং পোলকে সাধারণ রিকুয়েস্টের মতোই দেখে। প্রক্সির টাইমআউট এটি কেটে দিতে পারে, আর ক্যাশিং বন্ধ রাখতে হয় Source 1সোর্স 1।
  • সবচেয়ে মানানসই (tutorial's view): ফলব্যাক, বা বিরল আপডেট।

WebSocket

  • দিক: দুই দিকেই, একটি কানেকশনে Source 2সোর্স 2।
  • কীভাবে শুরু হয়: একটি HTTP Upgrade রিকুয়েস্ট, তারপর 101 Source 2সোর্স 2।
  • মেসেজ ফরম্যাট: টেক্সট বা বাইনারি ফ্রেম Source 2সোর্স 2।
  • রিকানেকশন: এটি ক্লায়েন্টের কাজ। ব্যাকঅফ ব্যবহার করুন Source 2সোর্স 2।
  • কানেকশনের সীমা (tutorial's view): এই পেজের সোর্সগুলো কোনো সংখ্যা দেয় না।
  • প্রক্সি: হ্যান্ডশেক এমনভাবে বানানো যে তা HTTP প্রক্সির সাথে কাজ করে Source 2সোর্স 2।
  • সবচেয়ে মানানসই (tutorial's view): চ্যাট, গেম, দ্বিমুখী ফ্লো।

SSE

  • দিক: শুধু সার্ভার থেকে ক্লায়েন্টের দিকে Source 5সোর্স 5।
  • কীভাবে শুরু হয়: একটি HTTP রিকুয়েস্ট, যার উত্তর আসে text/event-stream দিয়ে Source 5সোর্স 5।
  • মেসেজ ফরম্যাট: UTF-8 টেক্সট লাইন Source 3সোর্স 3।
  • রিকানেকশন: ব্রাউজার রিকানেক্ট করে। retry আর Last-Event-ID সাহায্য করে Source 3সোর্স 3।
  • কানেকশনের সীমা: HTTP/2 না হলে প্রতি ব্রাউজার ও ডোমেইনে প্রায় 6। HTTP/2-তে সীমা আলাপের মাধ্যমে (negotiate) ঠিক হয়, ডিফল্ট 100 Source 5সোর্স 5।
  • প্রক্সি: কিছু পুরোনো প্রক্সি নীরব (quiet) কানেকশন ফেলে দেয়। প্রায় প্রতি 15 সেকেন্ডে একটি কমেন্ট লাইন সাহায্য করে Source 3সোর্স 3।
  • সবচেয়ে মানানসই (tutorial's view): ফিড, নোটিশ, প্রগ্রেস।

A real-life example

This example is the tutorial's own. An exam platform shows a banner "your answers are saved", a progress page for the marking of a big test, and a chat with a proctor. The banner and the progress page need only server-to-client messages, so SSE can do them. The chat needs both directions, so a WebSocket fits.

সহজ English

This example is the tutorial's own. An exam platform shows a banner "your answers are saved". It also has a progress page for the marking of a big test, and a chat with a proctor. The banner and the progress page need only server-to-client messages, so SSE can do them. The chat needs both directions, so a WebSocket fits.

বাংলা ব্যাখ্যা

এই উদাহরণ টিউটোরিয়ালের নিজস্ব। একটি এক্সাম প্ল্যাটফর্ম "your answers are saved" লেখা একটি ব্যানার দেখায়। তাতে একটি বড় টেস্টের মার্কিংয়ের জন্য একটি প্রগ্রেস পেজ আর একজন প্রক্টরের সাথে একটি চ্যাটও আছে। ব্যানার আর প্রগ্রেস পেজের শুধু সার্ভার থেকে ক্লায়েন্টের দিকের মেসেজ দরকার, তাই SSE সেগুলো করতে পারে। চ্যাটে দুই দিকই দরকার, তাই WebSocket মানায়।

Common mistakes

সহজ English

বাংলা ব্যাখ্যা

  • ভাবা যে WebSocket চিরকাল খোলা থাকবে। অস্বাভাবিক বন্ধ হওয়া ঘটতে পারে, তাই ক্লায়েন্টের একটি রিকানেক্ট প্ল্যান দরকার Source 2সোর্স 2।
  • ক্লায়েন্ট থেকে ডেটা পাঠাতে SSE ব্যবহার করা। SSE একমুখী Source 5সোর্স 5।
  • প্রক্সি যতটা অনুমতি দেয়, তার চেয়ে বেশি পোল টাইমআউট ঠিক করা। ক্লায়েন্ট একটি 408 বা 504 পেতে পারে Source 1সোর্স 1।

What a tester can check

Tutorial advice

These test ideas are the tutorial's own advice, not a claim of the sources.

  • Cut the link. Drop the network for a moment. Check that the client reconnects, waits longer after each failure, and does not flood the server.
  • Look for lost messages. Send events while the client is offline. After it returns, check which events it misses.
  • Test the stop signals. For SSE, check what the page does after a 204 and after an error status.
  • Test behind a proxy. Use the same proxies as production, and watch for dropped idle connections.

সহজ English

These test ideas are the tutorial's own advice, not a claim of the sources.

  • Cut the link. Drop the network for a moment. Check that the client reconnects, waits longer after each failure, and does not flood the server.
  • Look for lost messages. Send events while the client is offline. After it returns, check which events it misses.
  • Test the stop signals. For SSE, check what the page does after a 204 and after an error status.
  • Test behind a proxy. Use the same proxies as production. Watch for dropped idle connections.

বাংলা ব্যাখ্যা

এই টেস্টের ধারণাগুলো টিউটোরিয়ালের নিজস্ব পরামর্শ, সোর্সের দাবি নয়।

  • লিংক কেটে দিন। কিছুক্ষণের জন্য নেটওয়ার্ক বন্ধ করুন। যাচাই করুন ক্লায়েন্ট রিকানেক্ট করে, প্রতিটি ফেইলিউরের পর আরও বেশি অপেক্ষা করে, এবং সার্ভারকে অতিরিক্ত রিকুয়েস্টে ভরে দেয় না।
  • হারানো মেসেজ খুঁজুন। ক্লায়েন্ট অফলাইন থাকার সময় ইভেন্ট পাঠান। সে ফিরে আসার পর দেখুন কোন ইভেন্ট সে পায়নি।
  • স্টপ সিগন্যাল টেস্ট করুন। SSE-র ক্ষেত্রে 204-এর পরে আর একটি এরর স্ট্যাটাসের পরে পেজ কী করে তা দেখুন।
  • প্রক্সির পেছনে টেস্ট করুন। প্রোডাকশনের মতো একই প্রক্সি ব্যবহার করুন। বাদ পড়া আইডল (idle) কানেকশন লক্ষ করুন।

Key words

WordMeaning
Long pollingThe server holds a request open and answers when it has something to send Source 1সোর্স 1
HTTP streamingThe server keeps a response open and sends data in pieces without ending it Source 1সোর্স 1
WebSocketA two-way channel that starts with an HTTP Upgrade request Source 2সোর্স 2
FrameA unit of a WebSocket message. It holds text, binary data, or a control signal Source 2সোর্স 2
Ping and PongWebSocket control frames. A Ping can serve as a keepalive Source 2সোর্স 2
Server-sent events (SSE)A one-way stream of events from server to browser, read through EventSource Source 5সোর্স 5
retryAn SSE field that sets the reconnection time in milliseconds Source 5সোর্স 5
Last-Event-IDThe request header that tells the server the last event ID, sent on reconnection Source 3সোর্স 3
BackpressureA way to slow the sender when the receiver is too slow. The WebSocket interface has none Source 4সোর্স 4

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    RFC 6202: Known Issues and Best Practices for the Use of Long Polling and Streaming in Bidirectional HTTP

    IETF, 2011 · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  2. [2]
    RFC 6455: The WebSocket Protocol

    IETF, 2011 · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  3. [3]
    HTML Living Standard, section 9.2: Server-sent events

    WHATWG · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  4. [4]
    WebSocket API (WebSockets)

    MDN Web Docs · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  5. [5]
    Using server-sent events

    MDN Web Docs · accessed 2026-10-22দেখা হয়েছে: 2026-10-22