I am using the Lidgren library in order to communicate strings throw computers over network. 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. The only output I get is 0.0.0.0 connected
after the newly connected client sends a message. Why isn't this working and how can I get notified when a new connection is established?
Call ReadMessage() on s_server; 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.