python-socketio icon indicating copy to clipboard operation
python-socketio copied to clipboard

Support for Socket.IO v4.1.0 inter-server communication (`serverSideEmit`)

Open Kakadus opened this issue 9 months ago • 1 comments

Is your feature request related to a problem? Please describe. In a multi-server scenario with a message queue such as redis or rabittmq, it is important to be able to send messages between servers. That is why socket.io 4.1 introduced the serverSideEmit function: https://github.com/dzad/socket.io/commit/491a9a0019540c5551935d5bf9b81fdaeba5e461. This seems to be missing from python-socketio though.

Ideally, parameters like room or to can limit the servers the message is sent to.

Describe the solution you'd like A sio.server_side_emit(..., to=..., room=...) function and self.server_side_emit(..., to=..., room=...) method to do inter-server communication.

Describe alternatives you've considered

  • adding clients between servers manually. This is not really feasible with dynamically scaled servers.
  • configuring the client manager manually. This seems not feasible either.

Additional context

# server A
await sio.server_side_emit("hello", "world", room="test")


# server B
@sio.on("hello")
async def server_notifications(sid, message):
    print(message)  # should print "world" if server is in room "test"

Kakadus avatar Mar 01 '25 22:03 Kakadus

This is not a top priority for me at this time, but I would be open to add this if someone contributes it.

But, I do not quite follow some of your requests:

Ideally, parameters like room or to can limit the servers the message is sent to.

What does it mean to send a server side emit to a room? If there are clients in that room, do they get the message? How do you add a server to a room? What do you pass in the to argument to reference a specific server? I don't see what is the point of this, or what problem does it solve.

miguelgrinberg avatar Mar 01 '25 23:03 miguelgrinberg