【发布时间】:2010-12-29 10:04:03
【问题描述】:
在一般聊天应用程序中,客户端的浏览器总是轮询服务器以检查新消息。
// the function to check new messages in server
function check(){
// but this question is less about jQuery.
$.ajax({
type: "POST",
url: "check.aspx",
data: "someparam=123",
success: function(msg){
// process msg here
// CHECK IT AGAIN, but sometimes we need to make delay here
check();
}
});
}
然后我读到了Nicholas Allen's blog about Keeping Connections Open in IIS。
这让我想到是否可以通过传输分块的 HTTP 将数据从我的服务器推送到客户端的浏览器(这意味着像流,对吗?)并 保持连接打开。
在保持连接打开的同时,在服务器中,我想保持运行以检查新消息。可能是这样的
while(connectionStillOpen) {
// any new message?
if( AnyMessage() )
{
// send chunked data, can I?
SendMessageToBrowser();
// may be we need to make delay here
Sleep(forSomeTime);
}
}
这是一个原始的想法。
在 ASP.net 中创建的我的聊天应用程序。由于我对 WCF 和高级 IIS 流模块的了解较少,我需要您的建议来实现这个想法。
是的,不可能可能就是答案。但如果仍然不可能,我需要知道为什么。
更新(3 年后):
这正是我想要的: Microsoft ASP.NET SignalR
【问题讨论】:
标签: asp.net wcf iis keep-alive