Javascript 向网站添加聊天功能

Javascript 向网站添加聊天功能,javascript,vb.net,xmlhttprequest,chat,polling,Javascript,Vb.net,Xmlhttprequest,Chat,Polling,我已经能够添加聊天功能到我的网站,但我想知道是否有一个更有效的方法来做到这一点。这是聊天室的当前结构: 带有javascript函数的HTML页面: sendChat(elmnt) { var result = XHR("http_sendChat.aspx","POST",0,elmnt); //xmlhttprequest to send chat message by posting elmnt string to page. 0 used for not polling } getC

我已经能够添加聊天功能到我的网站,但我想知道是否有一个更有效的方法来做到这一点。这是聊天室的当前结构:

带有javascript函数的HTML页面:

sendChat(elmnt) {
 var result = XHR("http_sendChat.aspx","POST",0,elmnt); //xmlhttprequest to send chat message by posting elmnt string to page. 0 used for not polling
}

getChat() {
 var result = XHR("http_getChat.aspx","GET",50,""); //polls page every 50ms to get new chat messages
 addMessageElmnt(result); //update chat window with new messages
}
在vb.net http_sendChat.aspx的服务器端:

Application.Lock
Application("chat") = Application("chat") & Request.Form("message") //Global application object stores chat log
Application.Unlock
Dim chatTemp
chatTemp = Mid(Application("chat"),Session("chatIndex")) //fetches whatever chat data hasn't been fetched yet
Session("chatIndex") = Session("chatIndex") + Len(chatTemp) //set index to last read position
Response.Write(chatTemp)
在vb.net http_getChat.aspx中的服务器端:

Application.Lock
Application("chat") = Application("chat") & Request.Form("message") //Global application object stores chat log
Application.Unlock
Dim chatTemp
chatTemp = Mid(Application("chat"),Session("chatIndex")) //fetches whatever chat data hasn't been fetched yet
Session("chatIndex") = Session("chatIndex") + Len(chatTemp) //set index to last read position
Response.Write(chatTemp)

还有更多的代码,主要是检查以确保用户帐户被激活,但就聊天而言,有没有更好的方法来做到这一点?我这样问是因为当大约有100人登录并使用聊天室时,速度相当慢。

你考虑过使用吗?你有没有理由不使用某种预先构建的聊天库或服务?尝试一下socket.io(他们有一个聊天示例要开始)我不知道是否有.net的后端驱动程序,你应该调查一下所有现代浏览器都支持WebSocket吗?如果有数百人连接,会更快吗?我觉得将相同的字符串写入100个套接字比将其写入100个用户从中读取的一个应用程序变量要慢。我不熟悉任何预先构建的聊天库或服务,如果您知道任何比我现在使用的更高效的聊天库或服务,我将不胜感激。这是我第一次创建任何类型的网络聊天,所以我正试图尽我所能解决它。