private void ConnectionListenerHandler() { //IPAddress localAddr = IPAddress.Parse("127.0.0.1"); try { server = NetworkUtility.GetTcpListener(System.Net.Dns.GetHostName(), port, out m_serverIP); //IPAddress[] addresses = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()); //server = new TcpListener(addresses[0], port); //System.Console.WriteLine("Hostname: " + System.Net.Dns.GetHostName()); //System.Console.WriteLine("ip address: " + addresses[0].ToString()); server.Start(); TcpClient client = null; NetworkServerConnectionHandler ch = null; while (state == ServerState.RUNNING) { System.Console.WriteLine("NetworkServer.ConnectionListenerHandler:listening for a connection..."); client = server.AcceptTcpClient(); System.Console.WriteLine("NetworkServer.ConnectionListenerHandler:connection established..."); ch = new NetworkServerConnectionHandler(ref client); ch.networkServer = this; lock (clientHandlersLock) { clientHandlers.Add(ch); } ch.Start(); } return; } catch (ThreadAbortException) { } catch (Exception exc) { MessageBox.Show("An error has occured in the Simulation Server.\nPlease email the C:\\DDDErrorLog.txt file to Aptima customer support with a description of what you were doing at the time of the error."); ErrorLog.Write(exc.ToString() + "\n"); throw new Exception(); } }
internal void RemoveClient(int clientID) { NetworkServerConnectionHandler found = null; lock (clientHandlersLock) { foreach (NetworkServerConnectionHandler ch in clientHandlers) { if (ch.ClientID() == clientID) { found = ch; break; } } } if (found != null) { lock (clientHandlersLock) { clientHandlers.Remove(found); eventDist.RemoveClient(clientID); } } }