Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Clarification needed on Rooms #535

Answered by Totodore
FaeyUmbrea asked this question in Q&A
Clarification needed on Rooms #535
Jun 27, 2025 * 1 comment
Answered by Totodore Return to top
Discussion options

FaeyUmbrea
Jun 27, 2025

I have been checking the documentation and the code but I still don't have a solid concept of how they behave exactly.

I have a codebase that only has at most 1 Socket per room. This is so I can easily emit messages sent to the socket.io server via an internal HTTP api to the user they are meant for (the room name is the userid and its autojoined on connect).

The behavior that would fit my usecase is:

  • If the HTTP api gets a message for a user that has never connected the message should be dropped
  • If a client disconnects it should also leave the room
  • For an emit_with_ack, I'd like to wait for any client to become available to recieve the message before it is dropped for 10 seconds. I do not want to loose the message if the client disconnected the instant before the event was transmitted, but I do not want to keep messages in memory indefinitely either

I am uncertain which of these are default behavior and which have to be manually implemented.

Messages aren't produced unless a client is connected, this is moreso to conserve memory (by avoiding queueing messages that will never be recieved) and ensure consitency (to avoid race conditions)

You must be logged in to vote

Hi! I recommend you to read this:
https://socket.io/docs/v4/rooms/.
This may help you to better understand rooms.
To answer your three questions:

  • When you broadcast a message to an inexistant room, it is dropped as there is no socket to send the message to.
  • Rooms are automatically cleaned each time a socket disconnects.
  • For your last point you need to manually implement something yourself maybe by checking if the socket exists with get_socket and emitting from it or storing it in a map of pending messages to send on the socket connection.

Don't hesitate if you need other clarifications.

View full answer

Replies: 1 comment

Comment options

Totodore
Jun 27, 2025
Maintainer

Hi! I recommend you to read this:
https://socket.io/docs/v4/rooms/.
This may help you to better understand rooms.
To answer your three questions:

  • When you broadcast a message to an inexistant room, it is dropped as there is no socket to send the message to.
  • Rooms are automatically cleaned each time a socket disconnects.
  • For your last point you need to manually implement something yourself maybe by checking if the socket exists with get_socket and emitting from it or storing it in a map of pending messages to send on the socket connection.

Don't hesitate if you need other clarifications.

You must be logged in to vote
0 replies
Answer selected by Totodore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants