5

I've just completed the simple chat client socket.io tutorial and I am inspecting the messages going between my browser and the Node.js server web socket using the Chrome WebSocket inspector. There are numbers prefixed before the messages as depicted in my screenshot below.

enter image description here

As you can see there are messages with just '2' and '3' and next to my emits there are 42s going back and forth. What do they mean? Is there a list of the main message types I should familiarise myself with so I can learn about debugging Web Sockets?

Evernoob
  • 5,551
  • 8
  • 37
  • 49
  • 2
    not a part of sockets spec, must be something added by your client software, socket.io. good luck finding more info: socket.io seems to be about half ritual and superstition... – dandavis Aug 17 '14 at 14:03
  • 2
    Possible duplicate: http://stackoverflow.com/questions/24564877/what-do-these-numbers-mean-in-socket-io-payload/ – Bogdan Aug 18 '14 at 18:45
  • @Evernoob: see my edit on the post above for extra details – Bogdan Aug 24 '14 at 11:38
  • 1
    Commented a moment ago by was really wrong. I found this tho: https://github.com/socketio/socket.io-protocol/issues/11 – Colin Smith Aug 03 '20 at 16:17
  • 1
    Does this answer your question? [What do these numbers mean in socket.io payload?](https://stackoverflow.com/questions/24564877/what-do-these-numbers-mean-in-socket-io-payload) – Patrick Sep 24 '22 at 02:29

1 Answers1

0

Duplicate question. As the comments say the number codes in your Websocket messages are not part of Websocket, they are added by the socket.io library.

The significance of numbers is found in engine.io protocol and the socket.io protocol, and described in other answers

engine.io protocol

So "just 2" and "just 3" you described are the "ping" and "pong"

Here is the list of available packet types:

Type ID Usage
open 0 Used during the handshake.
close 1 Used to indicate that a transport can be closed.
ping 2 Used in the heartbeat mechanism.
pong 3 Used in the heartbeat mechanism.
message 4 Used to send a payload to the other side.
upgrade 5 Used during the upgrade process.
noop 6 Used during the upgrade process.

socket.io protocol

So the "42" you described is a combination of engine.io 4, which means "message", and socket.io 2, which means "event"

Here is the list of available packet types:

Type ID Usage
CONNECT 0 Used during the connection to a namespace.
DISCONNECT 1 Used when disconnecting from a namespace.
EVENT 2 Used to send data to the other side.
ACK 3 Used to acknowledge an event.
CONNECT_ERROR 4 Used during the connection to a namespace.
BINARY_EVENT 5 Used to send binary data to the other side.
BINARY_ACK 6 Used to acknowledge an event (the response includes binary data).
Nate Anderson
  • 18,334
  • 18
  • 100
  • 135