Skip to content

Commit bd2ba23

Browse files
docs: clarify the session examples
1 parent 660263f commit bd2ba23

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

README.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Table of Contents:
1010

1111
- [Revision](#revision)
1212
- [Anatomy of an Engine.IO session](#anatomy-of-an-engineio-session)
13+
- [Sample session](#sample-session)
14+
- [Sample session with WebSocket only](#sample-session-with-websocket-only)
1315
- [URLs](#urls)
1416
- [Encoding](#encoding)
1517
- [Packet](#packet)
@@ -55,25 +57,7 @@ with `pong` packets.
5557
5. Polling transports can send a `close` packet to close the socket, since
5658
they're expected to be "opening" and "closing" all the time.
5759

58-
Example with WebSocket connection:
59-
60-
```
61-
GET /engine.io/?EIO=4&transport=websocket&sid=lv_VI97HAXpY6yYWAAAC
62-
< HTTP/1.1 101 Switching Protocols
63-
```
64-
65-
WebSocket frames:
66-
67-
```
68-
< 0{"sid":"lv_VI97HAXpY6yYWAAAC","pingInterval":25000,"pingTimeout":5000} => handshake
69-
> 4hello => message (not concatenated)
70-
> 4world
71-
< 2 => "ping" packet type
72-
> 3 => "pong" packet type
73-
> 1 => "close" packet type
74-
```
75-
76-
Example with polling:
60+
### Sample session
7761

7862
- Request n°1 (open packet)
7963

@@ -91,8 +75,12 @@ Details:
9175
{"sid":... => the handshake data
9276
```
9377

78+
Note: the `t` query param is used to ensure that the request is not cached by the browser.
79+
9480
- Request n°2 (message in):
9581

82+
`socket.send('hey')` is executed on the server:
83+
9684
```
9785
GET /engine.io/?EIO=4&transport=polling&t=N8hyd7H&sid=lv_VI97HAXpY6yYWAAAC
9886
< HTTP/1.1 200 OK
@@ -107,8 +95,12 @@ Details:
10795
hey => the actual message
10896
```
10997

98+
Note: the `sid` query param contains the sid sent in the handshake.
99+
110100
- Request n°3 (message out)
111101

102+
`socket.send('hello'); socket.send('world');` is executed on the client:
103+
112104
```
113105
POST /engine.io/?EIO=4&transport=polling&t=N8hzxke&sid=lv_VI97HAXpY6yYWAAAC
114106
> Content-Type: text/plain; charset=UTF-8
@@ -148,6 +140,28 @@ WebSocket frames:
148140
> 1 => "close" packet type
149141
```
150142

143+
### Sample session with WebSocket only
144+
145+
In that case, the client only enables WebSocket (without HTTP polling).
146+
147+
```
148+
GET /engine.io/?EIO=4&transport=websocket
149+
< HTTP/1.1 101 Switching Protocols
150+
```
151+
152+
WebSocket frames:
153+
154+
```
155+
< 0{"sid":"lv_VI97HAXpY6yYWAAAC","pingInterval":25000,"pingTimeout":5000} => handshake
156+
< 4hey
157+
> 4hello => message (not concatenated)
158+
> 4world
159+
< 2 => "ping" packet type
160+
> 3 => "pong" packet type
161+
> 1 => "close" packet type
162+
```
163+
164+
151165
## URLs
152166

153167
An Engine.IO url is composed as follows:

0 commit comments

Comments
 (0)