/// <summary> /// TCP/IP Server Thread that is listening for clients. /// </summary> private void ServerThreadStart() { // Client Socket variable; Socket clientSocket = null; TCPSocketListener socketListener = null; while (!m_stopServer) { try { // Wait for any client requests and if there is any // request from any client accept it (Wait indefinitely). //Bloqueante. Espera hasta nueva peticion de cliente o un close. clientSocket = m_server.AcceptSocket(); // Create a SocketListener object for the client. 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 (SocketException se) { m_stopServer = true; } } }
/// <summary> /// TCP/IP Server Thread that is listening for clients. /// </summary> private void ServerThreadStart() { // Client Socket variable; Socket clientSocket = null; TCPSocketListener socketListener = null; while (!m_stopServer) { try { // Wait for any client requests and if there is any // request from any client accept it (Wait indefinitely). clientSocket = m_server.AcceptSocket(); // Create a SocketListener object for the client. 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 (SocketException se) { m_stopServer = true; } } }
private void ServerThreadStart() { Socket clientSocket = null; TCPSocketListener listener = null; while (!this.m_stopServer) { try { clientSocket = this.m_server.AcceptSocket(); listener = new TCPSocketListener(clientSocket); lock (this.m_socketListenersList) { this.m_socketListenersList.Add(listener); } listener.StartSocketListener(); if (this.OnMessageToLog != null) { this.OnMessageToLog("TCP/IP Client Connected {" + clientSocket.RemoteEndPoint.ToString() + "}"); } continue; } catch (SocketException) { this.m_stopServer = true; continue; } } }