如何尽快检测断线,因为它在ASP.NET必有池? [英] How to detect a disconnection as soon as it happens on ASP.NET without pooling?
本文介绍了如何尽快检测断线,因为它在ASP.NET必有池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个服务器发送的事件在ASP.NET 处理程序
Response.ContentType = "text/event-stream";
while (true)
{
if(thereIsAMessage)
{
Response.Write(message);
Response.Flush();
if (Response.IsClientConnected == false)
{
break;
}
}
System.Threading.Thread.Sleep(1000);
}
问题是,我只能检测客户端断开连接时,我送点东西给客户端。而且我不希望轮询它,这违背了摆在首位使用服务器发送的事件的整个目的。
The problem is that I can only detect a client disconnection when I send something to the client. And I don't want to poll it, which defeats the whole purpose of using Server-sent events in the first place.
推荐答案
尝试一下 SignalR - 长期有效投票时,服务器通知将不难实现。可用时使用的WebSockets。你的情况可以用集线器来实现非常容易。
Try to look at SignalR - useful for long polling, server notifications won't be difficult to implement. Uses websockets when available. Yours scenario can be implemented very easily using hubs.
这篇关于如何尽快检测断线,因为它在ASP.NET必有池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文