在一般聊天应用程序中,客户端浏览器始终轮询服务器以检查新消息。通过http将数据从服务器推送到浏览器
// 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流模块的理解不够,我需要你的建议来实现这个想法。
是,不可能可能是答案。但我需要知道为什么如果它仍然不可能。
UPDATE(3年后):
这正是我一直在寻找: Microsoft ASP.NET SignalR
一个很好的资源。谢谢。 – 2009-12-23 09:10:06