StartSocketListener() public method

Method that starts SocketListener Thread.
public StartSocketListener ( ) : bool
return bool
コード例 #1
0
        /// <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, this);

                    // Start a communicating with the client in a different
                    // thread.
                    if (socketListener.StartSocketListener())
                    {
                        // Add the socket listener to an array list in a thread
                        // safe fashon.
                        //Monitor.Enter(m_socketListenersList);
                        lock (m_socketListenersList)
                        {
                            m_socketListenersList.Add(socketListener);
                            //Program.MainForm.AddConnection(clientSocket.RemoteEndPoint.ToString());
                        }
                    }
                    else
                    {
                        clientSocket.Disconnect(false);
                    }
                }
                catch (SocketException)
                {
                    m_stopServer = true;
                }
            }
        }
コード例 #2
0
ファイル: TCPServer.cs プロジェクト: AnthonyNystrom/MobiVU
        /// <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, this);

                    // Start a communicating with the client in a different
                    // thread.
                    if (socketListener.StartSocketListener())
                    {
                        // Add the socket listener to an array list in a thread
                        // safe fashon.
                        //Monitor.Enter(m_socketListenersList);
                        lock (m_socketListenersList)
                        {
                            m_socketListenersList.Add(socketListener);
                            //Program.MainForm.AddConnection(clientSocket.RemoteEndPoint.ToString());
                        }

                    }
                    else
                        clientSocket.Disconnect(false);
                }
                catch (SocketException)
                {
                    m_stopServer = true;
                }
            }
        }