By utilizing Socket.IO and the i0.emit() method it provides a seamless and interactive chat experience, allowing users to communicate with each other in real-time without delays.
You can still get the normal ‘listening on ${port}’, but you can also get alert as to when a user is connecting or disconnecting.
If you want to send a message to everyone except for a certain emitting socket, we have the broadcast flag for emitting from that socket:
io.on(‘connection’, (socket) => { socket.broadcast.emit(‘hi’); });
https://socket.io/get-started/chat/
A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of clients.
You can call join to subscribe the socket to a given channel:
io.on(“connection”, (socket) => { socket.join(“some room”); });
https://socket.io/docs/v4/rooms
To leave a channel you call leave in the same fashion as join.
A Namespace is a communication channel that allows you to split the logic of your application over a single shared connection (also called “multiplexing”).
Separate namespaces can enable targeted communication, efficient event handling, and scalability. It allows clients to connect and interact within their desired chat rooms while keeping the communication channels separate from each other.
Over the last couple articles, I’m starting to see why we were learning linked-list, stacks, and queues prior to moving into this event driven programing. I’m excited to see how they all work together.