/// <summary> /// TCP/IP Server Thread that is listening for clients. /// </summary> private void ServerThreadStart() { // Client Socket variable; while (!m_stopServer) { try { // Wait for any client requests and if there is any // request from any client accept it (Wait indefinitely). var clientSocket = m_server.AcceptSocket(); // Create a SocketListener object for the client. var socketListener = new TCPSocketListener(clientSocket); // Add the socket listener to an array list in a thread // safe fashon. //Monitor.Enter(m_socketListenersList); lock (m_socketListenersList) { m_socketListenersList.Add(socketListener); } //Monitor.Exit(m_socketListenersList); // Start a communicating with the client in a different // thread. socketListener.StartSocketListener(); } catch { m_stopServer = true; } } }