开发者社区> 问答> 正文

html5 websocket在线聊天

用html5 websocket 做的聊天室,怎么设置让客户端在知道服务器端的ip情况下,还是连不上呀!也就是说怎么对客户端进行身份验证?

展开
收起
云栖技术 2016-06-06 16:34:02 2473 0
1 条回答
写回答
取消 提交回答
  • 社区爱好者,专为云栖社区服务!
               while (true)
                {
                    Socket sc = Listener.Accept();
                    if (sc != null)
                    {
                        IPEndPoint cip = (IPEndPoint)sc.RemoteEndPoint;
                        string ipaddr = cip.Address.ToString();
    
                        if (ipaddr == "192.168.1.68")//这里改为你的其他判断,如读数据库中存在的ip地址对比什么的,在禁止ip列表里面就关闭连接
                            sc.Close();
                        else
                        {
                            System.Threading.Thread.Sleep(100);
                            SocketConnection socketConn = new SocketConnection();
                            socketConn.ConnectionSocket = sc;
                            socketConn.NewConnection += new NewConnectionEventHandler(socketConn_NewConnection);
                            socketConn.DataReceived += new DataReceivedEventHandler(socketConn_BroadcastMessage);
                            socketConn.Disconnected += new DisconnectedEventHandler(socketConn_Disconnected);
    
                            socketConn.ConnectionSocket.BeginReceive(socketConn.receivedDataBuffer,
                                                                     0, socketConn.receivedDataBuffer.Length,
                                                                     0, new AsyncCallback(socketConn.ManageHandshake),
                                                                     socketConn.ConnectionSocket.Available);
                            connectionSocketList.Add(socketConn);
    
                        }
                    }
    2019-07-17 19:28:57
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《零基础HTML入门教程》 立即下载
天猫 HTML5 互动技术实践 立即下载
天猫HTML5互动技术实践 立即下载