C#制作简单的多人在线即时交流聊天室

2019-12-30 11:19:21于海丽
  • }  }; 
  • ajax.send(param);  } 
  •   //获取AJAX对象(XMLHttpRequest) 
  • function getAjaxObject() {  var xmlhttp; 
  • if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp = new XMLHttpRequest(); 
  • }  else {// code for IE6, IE5 
  • xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  } 
  • return xmlhttp;  } 
  •   </script> 
  • </body>  </html> 

    代码很简单,并都有注释,在此就不作说明了,如果有疑问欢迎在下方评论。

    服务端(ChatHandler.ashx)

     

    1. <%@ WebHandler Language="C#" Class="ChatHandler" %>   
    2. using System;  using System.Web; 
    3. using System.Collections;  using System.Collections.Generic; 
    4. using System.Linq;  using System.Web.Script.Serialization; 
    5. using System.Threading;  using System.Collections.Concurrent; 
    6.   public class ChatHandler : IHttpHandler 
    7. {   
    8. private class Msg  { 
    9. public string name { get; set; }  public string sendtime { get; set; } 
    10. public string content { get; set; }  public string readednams { get; set; }