用html5 websocket 做的聊天室,怎么设置让客户端在知道服务器端的ip情况下,还是连不上呀!也就是说怎么对客户端进行身份验证?
2条回答
- Go 旅城通票 2014-12-08 07:52关注
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); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报