用html5 websocket 做的聊天室,怎么设置让客户端在知道服务器端的ip情况下,还是连不上呀!也就是说怎么对客户端进行身份验证?
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);
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。