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). |