admin管理员组文章数量:1026373
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.
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.
本文标签:
版权声明:本文标题:asp.net core - Why is it that all the examples i can find for WebSocket in C# have websocketHolder as a singleton? - Stack Overf 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745646590a2161061.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论