Socket.IO has another trick up its sleeve. We have been working in only one area so far, but Socket.IO has methods to connect to multiple areas. The first is namespaces. The other is rooms. Both of these ideas are very similar, and we will set both of them up.
We will use the same idea of users being able to ping, but we will add onto this idea. First of all, we will allow users to enter different areas and ping inside those areas. Secondly, we will allow users to send private pings that will only go to one specific user. For this, we will create a new project and start from scratch. We will use namespaces for the first project.
Here is all the boilerplate code that we need to do. Create a directory named second app
, files named namespace.js
and namespace.html
, and a symlink to the socket.io.js
client library (remember, it's in the node_modules
directory after you install Socket.IO).
We can now build our little app. We will start on the backend. Open up namespace.js
and...