用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); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
- ¥50 树莓派安卓APK系统签名
- ¥15 maple软件,用solve求反函数出现rootof,怎么办?
- ¥65 汇编语言除法溢出问题
- ¥15 Visual Studio问题
- ¥20 求一个html代码,有偿
- ¥100 关于使用MATLAB中copularnd函数的问题
- ¥20 在虚拟机的pycharm上
- ¥15 jupyterthemes 设置完毕后没有效果
- ¥15 matlab图像高斯低通滤波