Reading-Notes

Reading

Socket.io Chat Example

Explain to a non-technical recruiter what the Chat Example (above) does.

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.

What proof of life are we getting on the backend from the above app?

You can still get the normal ‘listening on ${port}’, but you can also get alert as to when a user is connecting or disconnecting.

Socket.IO gives us the i0.emit() method to send an event to everyone. What flag would you use if you want to send a message to everyone except for a certain emitting socket?

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/

Rooms

What is a room and how might a room be useful?

A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of clients.

How do you join a room?

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

How do you leave a room?

To leave a channel you call leave in the same fashion as join.

Namespaces

What is a Namespace and what does it allow you to do?

A Namespace is a communication channel that allows you to split the logic of your application over a single shared connection (also called “multiplexing”).

Each namespace potentially has its own what? (hint: 3 things)

Discuss a possible use case for separate namespaces

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.

Reflection

What are your learning goals after reading and reviewing the class README?

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.