asp.net core - Why is it that all the examples i can find for WebSocket in C# have websocketHolder as a singleton? - Stack Overf

Im trying to learn and understand on how to use websockets. And i have noticed that every tutorial and

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

In 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信