[英]Get notified when new connection is established with server
I am using the Lidgren library in order to communicate strings throw computers over network. 我正在使用Lidgren库 ,以便通过网络通信字符串抛出计算机。 I can get notified when a client disconnects from the server but I can not when a client connects. 当客户端与服务器断开连接时,我会收到通知,但是当客户端连接时,我不会收到通知。 I tried this piece of code running in a different thread : 我尝试了在不同线程中运行的这段代码:
static void connectionCheck()
{
if (server.ConnectionsCount != con)
{
for (int i = con; i < s_server.Connections.Count; i++)
{
Console.WriteLine(server.Connections[i].Peer.Configuration.LocalAddress.ToString() + " connected");
}
con = server.ConnectionsCount;
}
Thread.Sleep(1);
connectionCheck();
}
where con
is the old number of connections. 其中con
是旧的连接数。 The only output I get is 0.0.0.0 connected
after the newly connected client sends a message. 新连接的客户端发送消息后,我得到的唯一输出是0.0.0.0 connected
。 Why isn't this working and how can I get notified when a new connection is established? 为什么这不起作用?建立新连接后如何通知我?
Call ReadMessage() on s_server; 在s_server上调用ReadMessage(); when you receive a message of type StatusChanged, examine the first byte, it holds a NetConnectionStatus enum - if it's "Connected" then a remote peer just established a connection to this peer. 当您收到类型为StatusChanged的消息时,请检查第一个字节,其中包含一个NetConnectionStatus枚举-如果它是“ Connected”,则远程对等方刚刚建立了与该对等方的连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.