有关信号连接的问题

发布于 2025-01-21 09:00:47 字数 586 浏览 0 评论 0 原文

所有,

我都使用SignalR(.NET 6),并有一些有关SignalR连接的问题(特别是使用Web插座的SignalR连接):

Q#1) 如果SignalR客户端崩溃,SignalR Server会自动为我处置基础连接(并且将触发onDisconNectedAsync()事件)? 这个想法是要处理与每个连接有关的客户资源(在服务器上,资源EX:NHIBERNATE会话)。

我的测试指示(在本地计算机上,服务器和客户端):

我尝试模拟这种情况,在该方案中,我拥有一个运行的客户端,然后我使用任务管理器关闭了,并且Windows为流程发布了资源,Signalr Server以某种方式检测到了Signalr Server连接丢失并释放了连接,并呼唤了ondisconnectedAsync()。我不确定我的测试是否足以解决此用例(客户崩溃)。我很好奇服务器如何知道,这可能是客户连接的最终制度吗?

Q#2)如果客户端和服务器之间的当前连接被打破或中断,并且SignalR需要重新连接,并且成功重新连接,它是否使用相同的连接(具有相同的连接ID/相同的Web套接字)还是尝试创建新连接(与新的Web插座绑定)?

All,

I am using SignalR (.net 6) and have couple of questions about SignalR Connections (specifically SignalR connections that use web sockets):

Q #1)
If the SignalR client crashes, will SignalR server dispose the underlying connection automatically for me (and the OnDisconnectedAsync() event will be fired)?
The idea is to dispose client resources (on the server, resource ex: NHibernate session) that are tied to each connection.

My Tests Indicate (on local machine, both server and client):

I tried to simulate this scenario where I had a running client which then I shut down with Task manager and the minute Windows released resources for the process, the SignalR server somehow detected that connection was lost and released the connection and OnDisconnectedAsync() was called. I am not sure if my test was sufficient for this use case (client crash). I am curious of how did the server know, was it the fact the maybe the finalizer for client connection ran?

Q #2) If the current connection between client and server is broken or interrupted and SignalR needs to reconnect, and it successfully reconnects, does it use the same connection (with the same connection ID/same web socket) or does it attempt create new connection (tied to a new web socket)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咿呀咿呀哟 2025-01-28 09:00:47

服务器如果尚未收到消息(包括keep-alive aLALIVE)(包括keep-Alive) )在此间隔。由于如何实施,将客户端断开连接可能需要比此超时间隔更长。建议的值是Keepalive Interval值的两倍。

  1. 它分配了一个新的连接ID。考虑使用其他数据跟踪哪个用户,例如。检查ON连接和断开方法。
    https://learn.microsoft.com/ en-us/aspnet/core/signalr/groups?view = aspnetcore-6.0
  1. https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-6.0&tabs=dotnet

The server considers the client disconnected if it hasn't received a message (including keep-alive) in this interval. It could take longer than this timeout interval for the client to be marked disconnected due to how this is implemented. The recommended value is double the KeepAliveInterval value.

  1. It assigns a new connection id. Consider using other data to track which user is it, eg. Checking in the on connect and on disconnect methods.
    https://learn.microsoft.com/en-us/aspnet/core/signalr/groups?view=aspnetcore-6.0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文