[instant message]用asp.net+ jquery实现comet即时消息机制
2009-11-07 09:03
579 查看
效果图:
ajax
function SetParameters(p,pSplit)
{
var option={length:'200',title:'',help:'None'};
properties=p.split(pSplit);
for(i=0;i<properties.length;i++)
{
namevalue = properties[i].split(':');
if(namevalue.length >1)
{
execute ="option." + namevalue[0] +'=\''+ namevalue[1]+'\';';
eval(execute);
}
}
return option;
}
function CometClient(handler, publicToken, privateToken, onmessage, ontimeout, oncancelled, onerror)
{
this.lastMessageId = 1000;
this.publicToken = publicToken;
this.privateToken = privateToken;
this.handler = handler;
this.onmessage = onmessage;
this.ontimeout = ontimeout;
this.oncancelled = oncancelled;
this.onerror = onerror;
this.running = true;
}
CometClient.prototype.stopWaiting = function()
{
this.running = false;
}
CometClient.prototype.startWaiting = function()
{
this.running = true;
this.waitForMessages();
}
CometClient.prototype.waitForMessages = function()
{
var me = this;
$.ajax(
{
url: this.handler,
type: "POST",
data: { privateToken: this.privateToken, lastMessageId: this.lastMessageId },
success: function(response)
{
var messages =null;
if(response!=null&&response!="")
{
messages =SetParameters(response,";");
}
if (messages != null && messages.length > 0)
{
var keepWaiting = me.running;
for (var i = 0; i < 1; i++)
{
if (me.lastMessageId < messages.MessageId)
me.lastMessageId = messages.MessageId;
switch (messages.Name.toLowerCase())
{
case "timedout":
me.ontimeout();
break;
case "cancelled":
keepWaiting = false;
me.oncancelled();
break;
case "message":
me.onmessage(messages);
break;
}
}
if (keepWaiting)
me.waitForMessages();
}
},
error: function()
{
me.onerror();
}
});
}
下载演示代码
下载实现长连接的代码COMET.DLL
另外另一种实现方法 实现
FluorineFx + Flex 实现 效果如下。
http://ftp-woody.d134.6266668.cn/chat2.aspx
ajax
function SetParameters(p,pSplit)
{
var option={length:'200',title:'',help:'None'};
properties=p.split(pSplit);
for(i=0;i<properties.length;i++)
{
namevalue = properties[i].split(':');
if(namevalue.length >1)
{
execute ="option." + namevalue[0] +'=\''+ namevalue[1]+'\';';
eval(execute);
}
}
return option;
}
function CometClient(handler, publicToken, privateToken, onmessage, ontimeout, oncancelled, onerror)
{
this.lastMessageId = 1000;
this.publicToken = publicToken;
this.privateToken = privateToken;
this.handler = handler;
this.onmessage = onmessage;
this.ontimeout = ontimeout;
this.oncancelled = oncancelled;
this.onerror = onerror;
this.running = true;
}
CometClient.prototype.stopWaiting = function()
{
this.running = false;
}
CometClient.prototype.startWaiting = function()
{
this.running = true;
this.waitForMessages();
}
CometClient.prototype.waitForMessages = function()
{
var me = this;
$.ajax(
{
url: this.handler,
type: "POST",
data: { privateToken: this.privateToken, lastMessageId: this.lastMessageId },
success: function(response)
{
var messages =null;
if(response!=null&&response!="")
{
messages =SetParameters(response,";");
}
if (messages != null && messages.length > 0)
{
var keepWaiting = me.running;
for (var i = 0; i < 1; i++)
{
if (me.lastMessageId < messages.MessageId)
me.lastMessageId = messages.MessageId;
switch (messages.Name.toLowerCase())
{
case "timedout":
me.ontimeout();
break;
case "cancelled":
keepWaiting = false;
me.oncancelled();
break;
case "message":
me.onmessage(messages);
break;
}
}
if (keepWaiting)
me.waitForMessages();
}
},
error: function()
{
me.onerror();
}
});
}
下载演示代码
下载实现长连接的代码COMET.DLL
另外另一种实现方法 实现
FluorineFx + Flex 实现 效果如下。
http://ftp-woody.d134.6266668.cn/chat2.aspx
相关文章推荐
- [instant message]用asp.net+ jquery实现comet即时消息机制 ----转载woody.wu
- [新手上路] 使用ASP.NET MVC 4 Async Action + jQuery 实现消息通知机制
- 使用ASP.NET MVC 4 Async Action+jQuery实现消息通知机制的实现代码
- [新手上路] [原创]使用ASP.NET MVC 4 Async Action + jQuery 实现消息通知机制
- 使用ASP.NET MVC 4 Async Action+jQuery实现消息通知机制的实现代码
- Comet:Jquery+asp.net实现http长连接
- ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(五) 之 加好友,加群流程,消息管理和即时消息提示的实现
- Comet:Jquery+asp.net实现http长连接(LongPoll)
- Comet:Jquery+asp.net实现http长连接(LongPoll)
- Asp.net实现即时消息通讯(Ajax)
- Asp.net实现即时消息通讯(Ajax)
- Comet:Jquery+asp.net实现http长连接(LongPoll)
- iis/asp.net服务器iPhone消息推送机制实现与探讨
- ASP.NET SignaiR 实现消息的即时推送,并使用Push.js实现通知的示例代码
- .NET 1.1中预编译ASP.NET页面实现原理浅析 [1] 自动预编译机制浅析
- 用 ASP.NET MVC 实现基于 Multipart XMLHttpRequest 的 Comet
- AngularJS+ASP.NET MVC+SignalR实现消息推送
- comet在asp.net中的实现
- asp.net(c#)实现邀请码机制
- ASP.NET jQuery 随笔 使用allValidator插件简单实现客户端验证功能