Skip to content

Readings: Socket.io Namespaces and Roomsv2

Jacob-Wendt edited this page Jul 2, 2019 · 1 revision

Socket.io

Default namespace

  • the default namespace is / and it’s the one Socket.IO clients connect to by default, and the one the server listens to by default.
  • Each namespace emits a connection event that receives each Socket instance as a parameter

Custom namespaces

  • To set up a custom namespace, you can call the of function on the server-side
  • On the client side, you tell Socket.IO client to connect to that namespace
  • The namespace is an implementation detail of the Socket.IO protocol, and is not related to the actual URL of the underlying transport, which defaults to /socket.io/…

Rooms

  • Within each namespace, you can also define arbitrary channels that sockets can join and leave

Joining and leaving

  • You can call join to subscribe the socket to a given channel
  • And then simply use to or in (they are the same) when broadcasting or emitting

Clone this wiki locally