Best way of handling Websocket "rooms" and responding to multiple clients #308
-
I'm working on a turn-based game where I want to broadcast server responses to particular subsets of clients, being part of the same game session or "room". I've just created a simple setup following the docs, but I'm stuck on how/where to handle this. Unless I'm missing something, I'll proceed with something along the following lines: My simple server bootstrapping for reference:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, finally the first topic in the discussions channel! 🙃 The framework by design doesn't handle any form of channel/room support. It is up to the developer to implement this or reuse an existing solution (available somewhere? 🙈 ). If I would like to face this problem I would start with some code-responsibility detection.
Why it is better to handle connections via Maybe I can monkey-patch the |
Beta Was this translation helpful? Give feedback.
Hi, finally the first topic in the discussions channel! 🙃
The framework by design doesn't handle any form of channel/room support. It is up to the developer to implement this or reuse an existing solution (available somewhere? 🙈 ). If I would like to face this problem I would start with some code-responsibility detection.
You can reuse the DI mechanism and define a dependency/reader that will manage all incoming/outgoing and existing connections, eg. it doesn't mean that you have to store them explicitly - it is already managed by an instance of
WebSocketServerConnection
which is just an extension ofws
WebSocket.Server
interface. See docs. Each stored client has its ownid
property, ad…