Understanding Socket.IO events
Socket.IO is an event-driven module or library, and, as you probably guessed, is based on EventEmitter
. Everything in Socket.IO works with events. An event is triggered when a new connection is made to the Socket.IO server and an event can be emitted to send data to the client.
The Socket.IO server API differs from the Socket.IO client API. However, both work with events to send data from client to server and vice versa.
The Socket.IO server events
Socket.IO uses a single TCP connection to a single path. That means, by default, the connection is made to the URL http[s]://host:port/socket.io
. However, within Socket.IO, it allows you to define namespaces. That means, different end-points but the connection will still remain a single URL.
Note
By default, Socket.IO Server uses the "/"
or root namespace
You can, of course, define multiple instances and listen to different URLs as well. However, we will assume, for the purpose of this recipe, that only one connection...