You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-11Lines changed: 52 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -18,14 +18,16 @@ Table of Contents:
18
18
- [2 ping](#2-ping)
19
19
- [3 pong](#3-pong)
20
20
- [4 message](#4-message)
21
+
- [5 upgrade](#5-upgrade)
22
+
- [6 noop](#6-noop)
21
23
-[Payload](#payload)
22
24
-[Transports](#transports)
23
25
-[Polling](#polling)
24
26
- [XHR](#xhr)
25
27
- [JSONP](#jsonp)
26
28
-[Server-sent events](#server-sent-events)
27
29
-[WebSocket](#websocket)
28
-
-[Transport fallback](#transport-fallback)
30
+
-[Transport upgrading](#transport-upgrading)
29
31
-[Timeouts](#timeouts)
30
32
-[Difference between v3 and v4](#difference-between-v3-and-v4)
31
33
-[Difference between v2 and v3](#difference-between-v2-and-v3)
@@ -126,7 +128,25 @@ hello => the 1st message
126
128
world => the 2nd message
127
129
```
128
130
131
+
- Request n°4 (WebSocket upgrade)
129
132
133
+
```
134
+
GET /engine.io/?EIO=3&transport=websocket&sid=lv_VI97HAXpY6yYWAAAC
135
+
< HTTP/1.1 101 Switching Protocols
136
+
```
137
+
138
+
WebSocket frames:
139
+
140
+
```
141
+
< 2probe => probe request
142
+
> 3probe => probe response
143
+
> 5 => "upgrade" packet type
144
+
> 4hello => message (not concatenated)
145
+
> 4world
146
+
> 2 => "ping" packet type
147
+
< 3 => "pong" packet type
148
+
> 1 => "close" packet type
149
+
```
130
150
131
151
## URLs
132
152
@@ -219,6 +239,23 @@ actual message, client and server should call their callbacks with the data.
219
239
1. client sends: ```4HelloWorld```
220
240
2. server receives and calls callback ```socket.on('message', function (data) { console.log(data); });```
221
241
242
+
#### 5 upgrade
243
+
244
+
Before engine.io switches a transport, it tests, if server and client can communicate over this transport.
245
+
If this test succeed, the client sends an upgrade packets which requests the server to flush its cache on
246
+
the old transport and switch to the new transport.
247
+
248
+
#### 6 noop
249
+
250
+
A noop packet. Used primarily to force a poll cycle when an incoming websocket connection is received.
251
+
252
+
##### example
253
+
1. client connects through new transport
254
+
2. client sends ```2probe```
255
+
3. server receives and sends ```3probe```
256
+
4. client receives and sends ```5```
257
+
5. server flushes and closes old transport and switches to new.
258
+
222
259
### Payload
223
260
224
261
A payload is a series of encoded packets tied together. The payload encoding format is as follows when only strings are sent and XHR2 is not supported:
@@ -356,13 +393,23 @@ already has a lightweight framing mechanism.
356
393
In order to send a payload of messages, encode packets individually
357
394
and `send()` them in succession.
358
395
359
-
## Transport fallback
396
+
## Transport upgrading
360
397
361
-
A connection always starts with WebSocket (if supported by the client).
398
+
A connection always starts with polling (either XHR or JSONP). WebSocket
399
+
gets tested on the side by sending a probe. If the probe is responded
400
+
from the server, an upgrade packet is sent.
362
401
363
-
If the connection cannot be established, the client will try to establish a SSE stream.
402
+
To ensure no messages are lost, the upgrade packet will only be sent
403
+
once all the buffers of the existing transport are flushed and the
404
+
transport is considered _paused_.
364
405
365
-
If the connection still fails, the client will use polling as a fallback (either XHR or JSONP).
406
+
When the server receives the upgrade packet, it must assume this is the
407
+
new transport channel and send all existing buffers (if any) to it.
408
+
409
+
The probe sent by the client is a `ping` packet with `probe` sent as data.
410
+
The probe sent by the server is a `pong` packet with `probe` sent as data.
411
+
412
+
Moving forward, upgrades other than just `polling -> x` are being considered.
366
413
367
414
## Timeouts
368
415
@@ -386,12 +433,6 @@ does not receive any data within `pingTimeout + pingInterval`.
386
433
The ping packets will now be sent by the server, because the timers set in the browsers are not reliable enough. We
387
434
suspect that a lot of timeout problems came from timers being delayed on the client-side.
388
435
389
-
- fallback to polling instead of upgrading to WebSocket
390
-
391
-
As of today, most browsers now support WebSocket: https://caniuse.com/#search=websocket
392
-
393
-
Please note that this does not remove the need to use sticky-session for the polling transport.
394
-
395
436
- always use base64 when encoding a payload with binary data
396
437
397
438
This change allows to treat all payloads (with or without binary) the same way, without having to take in account
0 commit comments