{"id":14978139,"url":"https://github.com/socketio/engine.io-protocol","last_synced_at":"2026-03-09T20:02:41.602Z","repository":{"id":6456597,"uuid":"7696299","full_name":"socketio/engine.io-protocol","owner":"socketio","description":"Engine.IO protocol","archived":false,"fork":false,"pushed_at":"2024-07-01T19:55:24.000Z","size":126,"stargazers_count":248,"open_issues_count":2,"forks_count":46,"subscribers_count":86,"default_branch":"main","last_synced_at":"2026-02-13T02:42:33.900Z","etag":null,"topics":["javascript","nodejs","websocket"],"latest_commit_sha":null,"homepage":"https://socket.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/socketio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-01-18T23:18:25.000Z","updated_at":"2025-11-28T11:00:21.000Z","dependencies_parsed_at":"2024-09-18T23:04:50.040Z","dependency_job_id":null,"html_url":"https://github.com/socketio/engine.io-protocol","commit_stats":{"total_commits":80,"total_committers":13,"mean_commits":6.153846153846154,"dds":0.7125,"last_synced_commit":"f21de7b00ed09b3bbad2807db718ea5d6bc36aba"},"previous_names":["learnboost/engine.io-protocol"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/socketio/engine.io-protocol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fengine.io-protocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fengine.io-protocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fengine.io-protocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fengine.io-protocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socketio","download_url":"https://codeload.github.com/socketio/engine.io-protocol/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fengine.io-protocol/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30310000,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T17:35:44.120Z","status":"ssl_error","status_checked_at":"2026-03-09T17:35:43.707Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","nodejs","websocket"],"created_at":"2024-09-24T13:56:55.656Z","updated_at":"2026-03-09T20:02:41.565Z","avatar_url":"https://github.com/socketio.png","language":"JavaScript","readme":"# Engine.IO Protocol\n\nThis document describes the 4th version of the Engine.IO protocol.\n\n**Table of content**\n\n- [Introduction](#introduction)\n- [Transports](#transports)\n  - [HTTP long-polling](#http-long-polling)\n    - [Request path](#request-path)\n    - [Query parameters](#query-parameters)\n    - [Headers](#headers)\n    - [Sending and receiving data](#sending-and-receiving-data)\n      - [Sending data](#sending-data)\n      - [Receiving data](#receiving-data)\n  - [WebSocket](#websocket)\n- [Protocol](#protocol)\n  - [Handshake](#handshake)\n  - [Heartbeat](#heartbeat)\n  - [Upgrade](#upgrade)\n  - [Message](#message)\n- [Packet encoding](#packet-encoding)\n  - [HTTP long-polling](#http-long-polling-1)\n  - [WebSocket](#websocket-1)\n- [History](#history)\n  - [From v2 to v3](#from-v2-to-v3)\n  - [From v3 to v4](#from-v3-to-v4)\n- [Test suite](#test-suite)\n\n\n\n## Introduction\n\nThe Engine.IO protocol enables [full-duplex](https://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX) and low-overhead communication between a client and a server.\n\nIt is based on the [WebSocket protocol](https://en.wikipedia.org/wiki/WebSocket) and uses [HTTP long-polling](https://en.wikipedia.org/wiki/Push_technology#Long_polling) as fallback if the WebSocket connection can't be established.\n\nThe reference implementation is written in [TypeScript](https://www.typescriptlang.org/):\n\n- server: https://github.com/socketio/engine.io\n- client: https://github.com/socketio/engine.io-client\n\nThe [Socket.IO protocol](https://github.com/socketio/socket.io-protocol) is built on top of these foundations, bringing additional features over the communication channel provided by the Engine.IO protocol.\n\n## Transports\n\nThe connection between an Engine.IO client and an Engine.IO server can be established with:\n\n- [HTTP long-polling](#http-long-polling)\n- [WebSocket](#websocket)\n\n### HTTP long-polling\n\nThe HTTP long-polling transport (also simply referred as \"polling\") consists of successive HTTP requests:\n\n- long-running `GET` requests, for receiving data from the server\n- short-running `POST` requests, for sending data to the server\n\n#### Request path\n\nThe path of the HTTP requests is `/engine.io/` by default.\n\nIt might be updated by libraries built on top of the protocol (for example, the Socket.IO protocol uses `/socket.io/`).\n\n#### Query parameters\n\nThe following query parameters are used:\n\n| Name        | Value     | Description                                                        |\n|-------------|-----------|--------------------------------------------------------------------|\n| `EIO`       | `4`       | Mandatory, the version of the protocol.                            | \n| `transport` | `polling` | Mandatory, the name of the transport.                              |\n| `sid`       | `\u003csid\u003e`   | Mandatory once the session is established, the session identifier. |\n\nIf a mandatory query parameter is missing, then the server MUST respond with an HTTP 400 error status.\n\n#### Headers\n\nWhen sending binary data, the sender (client or server) MUST include a `Content-Type: application/octet-stream` header.\n\nWithout an explicit `Content-Type` header, the receiver SHOULD infer that the data is plaintext.\n\nReference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type\n\n#### Sending and receiving data\n\n##### Sending data\n\nTo send some packets, a client MUST create an HTTP `POST` request with the packets encoded in the request body:\n\n```\nCLIENT                                                 SERVER\n\n  │                                                      │\n  │   POST /engine.io/?EIO=4\u0026transport=polling\u0026sid=...   │\n  │ ───────────────────────────────────────────────────► │\n  │ ◄──────────────────────────────────────────────────┘ │\n  │                        HTTP 200                      │\n  │                                                      │\n```\n\nThe server MUST return an HTTP 400 response if the session ID (from the `sid` query parameter) is not known.\n\nTo indicate success, the server MUST return an HTTP 200 response, with the string `ok` in the response body.\n\nTo ensure packet ordering, a client MUST NOT have more than one active `POST` request. Should it happen, the server MUST return an HTTP 400 error status and close the session.\n\n##### Receiving data\n\nTo receive some packets, a client MUST create an HTTP `GET` request:\n\n```\nCLIENT                                                SERVER\n\n  │   GET /engine.io/?EIO=4\u0026transport=polling\u0026sid=...   │\n  │ ──────────────────────────────────────────────────► │\n  │                                                   . │\n  │                                                   . │\n  │                                                   . │\n  │                                                   . │\n  │ ◄─────────────────────────────────────────────────┘ │\n  │                       HTTP 200                      │\n```\n\nThe server MUST return an HTTP 400 response if the session ID (from the `sid` query parameter) is not known.\n\nThe server MAY not respond right away if there are no packets buffered for the given session. Once there are some packets to be sent, the server SHOULD encode them (see [Packet encoding](#packet-encoding)) and send them in the response body of the HTTP request.\n\nTo ensure packet ordering, a client MUST NOT have more than one active `GET` request. Should it happen, the server MUST return an HTTP 400 error status and close the session.\n\n### WebSocket\n\nThe WebSocket transport consists of a [WebSocket connection](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API), which provides a bidirectional and low-latency communication channel between the server and the client.\n\nThe following query parameters are used:\n\n| Name        | Value       | Description                                                                   |\n|-------------|-------------|-------------------------------------------------------------------------------|\n| `EIO`       | `4`         | Mandatory, the version of the protocol.                                       | \n| `transport` | `websocket` | Mandatory, the name of the transport.                                         |\n| `sid`       | `\u003csid\u003e`     | Optional, depending on whether it's an upgrade from HTTP long-polling or not. |\n\nIf a mandatory query parameter is missing, then the server MUST close the WebSocket connection.\n\nEach packet (read or write) is sent its own [WebSocket frame](https://datatracker.ietf.org/doc/html/rfc6455#section-5).\n\nA client MUST NOT open more than one WebSocket connection per session. Should it happen, the server MUST close the WebSocket connection.\n\n## Protocol\n\nAn Engine.IO packet consists of:\n\n- a packet type\n- an optional packet payload\n\nHere is the list of available packet types:\n\n| Type    | ID  | Usage                                            |\n|---------|-----|--------------------------------------------------|\n| open    | 0   | Used during the [handshake](#handshake).         | \n| close   | 1   | Used to indicate that a transport can be closed. |\n| ping    | 2   | Used in the [heartbeat mechanism](#heartbeat).   |\n| pong    | 3   | Used in the [heartbeat mechanism](#heartbeat).   |\n| message | 4   | Used to send a payload to the other side.        |\n| upgrade | 5   | Used during the [upgrade process](#upgrade).     |\n| noop    | 6   | Used during the [upgrade process](#upgrade).     |\n\n### Handshake\n\nTo establish a connection, the client MUST send an HTTP `GET` request to the server:\n\n- HTTP long-polling first (by default)\n\n```\nCLIENT                                                    SERVER\n\n  │                                                          │\n  │        GET /engine.io/?EIO=4\u0026transport=polling           │\n  │ ───────────────────────────────────────────────────────► │\n  │ ◄──────────────────────────────────────────────────────┘ │\n  │                        HTTP 200                          │\n  │                                                          │\n```\n\n- WebSocket-only session\n\n```\nCLIENT                                                    SERVER\n\n  │                                                          │\n  │        GET /engine.io/?EIO=4\u0026transport=websocket         │\n  │ ───────────────────────────────────────────────────────► │\n  │ ◄──────────────────────────────────────────────────────┘ │\n  │                        HTTP 101                          │\n  │                                                          │\n```\n\nIf the server accepts the connection, then it MUST respond with an `open` packet with the following JSON-encoded payload:\n\n| Key            | Type       | Description                                                                                                       |\n|----------------|------------|-------------------------------------------------------------------------------------------------------------------|\n| `sid`          | `string`   | The session ID.                                                                                                   |\n| `upgrades`     | `string[]` | The list of available [transport upgrades](#upgrade).                                                             |\n| `pingInterval` | `number`   | The ping interval, used in the [heartbeat mechanism](#heartbeat) (in milliseconds).                               |\n| `pingTimeout`  | `number`   | The ping timeout, used in the [heartbeat mechanism](#heartbeat) (in milliseconds).                                |\n| `maxPayload`   | `number`   | The maximum number of bytes per chunk, used by the client to aggregate packets into [payloads](#packet-encoding). |\n\nExample:\n\n```json\n{\n  \"sid\": \"lv_VI97HAXpY6yYWAAAC\",\n  \"upgrades\": [\"websocket\"],\n  \"pingInterval\": 25000,\n  \"pingTimeout\": 20000,\n  \"maxPayload\": 1000000\n}\n```\n\nThe client MUST send the `sid` value in the query parameters of all subsequent requests.\n\n### Heartbeat\n\nOnce the [handshake](#handshake) is completed, a heartbeat mechanism is started to check the liveness of the connection:\n\n```\nCLIENT                                                 SERVER\n\n  │                   *** Handshake ***                  │\n  │                                                      │\n  │  ◄─────────────────────────────────────────────────  │\n  │                           2                          │  (ping packet)\n  │  ─────────────────────────────────────────────────►  │\n  │                           3                          │  (pong packet)\n```\n\nAt a given interval (the `pingInterval` value sent in the handshake) the server sends a `ping` packet and the client has a few seconds (the `pingTimeout` value) to send a `pong` packet back.\n\nIf the server does not receive a `pong` packet back, then it SHOULD consider that the connection is closed.\n\nConversely, if the client does not receive a `ping` packet within `pingInterval + pingTimeout`, then it SHOULD consider that the connection is closed.\n\n### Upgrade\n\nBy default, the client SHOULD create an HTTP long-polling connection, and then upgrade to better transports if available.\n\nTo upgrade to WebSocket, the client MUST:\n\n- pause the HTTP long-polling transport (no more HTTP request gets sent), to ensure that no packet gets lost\n- open a WebSocket connection with the same session ID\n- send a `ping` packet with the string `probe` in the payload\n\nThe server MUST:\n\n- send a `noop` packet to any pending `GET` request (if applicable) to cleanly close HTTP long-polling transport\n- respond with a `pong` packet with the string `probe` in the payload\n\nFinally, the client MUST send a `upgrade` packet to complete the upgrade:\n\n```\nCLIENT                                                 SERVER\n\n  │                                                      │\n  │   GET /engine.io/?EIO=4\u0026transport=websocket\u0026sid=...  │\n  │ ───────────────────────────────────────────────────► │\n  │  ◄─────────────────────────────────────────────────┘ │\n  │            HTTP 101 (WebSocket handshake)            │\n  │                                                      │\n  │            -----  WebSocket frames -----             │\n  │  ─────────────────────────────────────────────────►  │\n  │                         2probe                       │ (ping packet)\n  │  ◄─────────────────────────────────────────────────  │\n  │                         3probe                       │ (pong packet)\n  │  ─────────────────────────────────────────────────►  │\n  │                         5                            │ (upgrade packet)\n  │                                                      │\n```\n\n### Message\n\nOnce the [handshake](#handshake) is completed, the client and the server can exchange data by including it in a `message` packet.\n\n\n## Packet encoding\n\nThe serialization of an Engine.IO packet depends on the type of the payload (plaintext or binary) and on the transport.\n\nThe character encoding is UTF-8 for plain text and for base64-encoded binary payloads.\n\n### HTTP long-polling\n\nDue to the nature of the HTTP long-polling transport, multiple packets might be concatenated in a single payload in order to increase throughput.\n\nFormat:\n\n```\n\u003cpacket type\u003e[\u003cdata\u003e]\u003cseparator\u003e\u003cpacket type\u003e[\u003cdata\u003e]\u003cseparator\u003e\u003cpacket type\u003e[\u003cdata\u003e][...]\n```\n\nExample:\n\n```\n4hello\\x1e2\\x1e4world\n\nwith:\n\n4      =\u003e message packet type\nhello  =\u003e message payload\n\\x1e   =\u003e separator\n2      =\u003e ping packet type\n\\x1e   =\u003e separator\n4      =\u003e message packet type\nworld  =\u003e message payload\n```\n\nThe packets are separated by the [record separator character](https://en.wikipedia.org/wiki/C0_and_C1_control_codes#Field_separators): `\\x1e`\n\nBinary payloads MUST be base64-encoded and prefixed with a `b` character:\n\nExample:\n\n```\n4hello\\x1ebAQIDBA==\n\nwith:\n\n4         =\u003e message packet type\nhello     =\u003e message payload\n\\x1e      =\u003e separator\nb         =\u003e binary prefix\nAQIDBA==  =\u003e buffer \u003c01 02 03 04\u003e encoded as base64\n```\n\nThe client SHOULD use the `maxPayload` value sent during the [handshake](#handshake) to decide how many packets should be concatenated.\n\n### WebSocket\n\nEach Engine.IO packet is sent in its own [WebSocket frame](https://datatracker.ietf.org/doc/html/rfc6455#section-5).\n\nFormat:\n\n```\n\u003cpacket type\u003e[\u003cdata\u003e]\n```\n\nExample:\n\n```\n4hello\n\nwith:\n\n4      =\u003e message packet type\nhello  =\u003e message payload (UTF-8 encoded)\n```\n\nBinary payloads are sent as is, without modification.\n\n## History\n\n### From v2 to v3\n\n- add support for binary data\n\nThe [2nd version](https://github.com/socketio/engine.io-protocol/tree/v2) of the protocol is used in Socket.IO `v0.9` and below.\n\nThe [3rd version](https://github.com/socketio/engine.io-protocol/tree/v3) of the protocol is used in Socket.IO `v1` and `v2`.\n\n### From v3 to v4\n\n- reverse ping/pong mechanism\n\nThe ping packets are now sent by the server, because the timers set in the browsers are not reliable enough. We\nsuspect that a lot of timeout problems came from timers being delayed on the client-side.\n\n- always use base64 when encoding a payload with binary data\n\nThis change allows to treat all payloads (with or without binary) the same way, without having to take in account\nwhether the client or the current transport supports binary data or not.\n\nPlease note that this only applies to HTTP long-polling. Binary data is sent in WebSocket frames with no additional transformation.\n\n- use a record separator (`\\x1e`) instead of counting of characters\n\nCounting characters prevented (or at least makes harder) to implement the protocol in other languages, which may not use\nthe UTF-16 encoding.\n\nFor example, `€` was encoded to `2:4€`, though `Buffer.byteLength('€') === 3`.\n\nNote: this assumes the record separator is not used in the data.\n\nThe 4th version (current) is included in Socket.IO `v3` and above.\n\n## Test suite\n\nThe test suite in the `test-suite/` directory lets you check the compliance of a server implementation.\n\nUsage:\n\n- in Node.js: `npm ci \u0026\u0026 npm test`\n- in a browser: simply open the `index.html` file in your browser\n\nFor reference, here is expected configuration for the JavaScript server to pass all tests:\n\n```js\nimport { listen } from \"engine.io\";\n\nconst server = listen(3000, {\n  pingInterval: 300,\n  pingTimeout: 200,\n  maxPayload: 1e6,\n  cors: {\n    origin: \"*\"\n  }\n});\n\nserver.on(\"connection\", socket =\u003e {\n  socket.on(\"data\", (...args) =\u003e {\n    socket.send(...args);\n  });\n});\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fengine.io-protocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketio%2Fengine.io-protocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fengine.io-protocol/lists"}