所有,
我都使用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)?
发布评论
评论(1)
服务器如果尚未收到消息(包括keep-alive aLALIVE)(包括keep-Alive) )在此间隔。由于如何实施,将客户端断开连接可能需要比此超时间隔更长。建议的值是Keepalive Interval值的两倍。
https://learn.microsoft.com/ en-us/aspnet/core/signalr/groups?view = aspnetcore-6.0
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.
https://learn.microsoft.com/en-us/aspnet/core/signalr/groups?view=aspnetcore-6.0