Im trying to learn and understand on how to use websockets. And i have noticed that every tutorial and example i have seen have the holder class for websocket registred as a singleton.
Why doesent each connection have its own handler? I think that would make it more easier to handle concurrent data. for ex a chat application where multiple user send messages at the same time, or multiple parallel chatrooms, etc.
To me it seems like a bottleneck, that when server is accepting data from 1 client, all the other connections have to wait. Or am i mistaken?
Im trying to learn and understand on how to use websockets. And i have noticed that every tutorial and example i have seen have the holder class for websocket registred as a singleton.
Why doesent each connection have its own handler? I think that would make it more easier to handle concurrent data. for ex a chat application where multiple user send messages at the same time, or multiple parallel chatrooms, etc.
To me it seems like a bottleneck, that when server is accepting data from 1 client, all the other connections have to wait. Or am i mistaken?
Share Improve this question asked Nov 16, 2024 at 19:00 Marko TahtMarko Taht 1,5361 gold badge21 silver badges52 bronze badges1 Answer
Reset to default 0In most WebSocket examples in C#, a singleton is used to manage connections to make things simpler and to have a central point for managing all connections. However, this doesn't mean that all connections have to wait for each other. WebSockets work concurrently, meaning when a message comes from one client, the server can process it without blocking the other connections. The use of a singleton is just for better and centralized management, not to cause delays or blocking of other connections.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745646591a4638007.html
评论列表(0条)