VideoCallServer.TCPServer.StopServer C# (CSharp) Method

StopServer() public method

Method that stops the TCP/IP Server.
public StopServer ( ) : void
return void
        public void StopServer()
        {
            if (m_server != null)
            {
                // It is important to Stop the server first before doing
                // any cleanup. If not so, clients might being added as
                // server is running, but supporting data structures
                // (such as m_socketListenersList) are cleared. This might
                // cause exceptions.

                // Stop the TCP/IP Server.
                m_stopServer = true;
                m_server.Stop();

                // Wait for one second for the the thread to stop.
                m_serverThread.Join(1000);

                // If still alive; Get rid of the thread.
                if (m_serverThread.IsAlive)
                {
                    m_serverThread.Abort();
                }
                m_serverThread = null;

                m_stopPurging = true;
                m_purgingThread.Join(1000);
                if (m_purgingThread.IsAlive)
                {
                    m_purgingThread.Abort();
                }
                m_purgingThread = null;

                // Free Server Object.
                m_server = null;

                // Stop All clients.
                StopAllSocketListers();
            }
        }

Usage Example

Esempio n. 1
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     _udpServer.StopServer();
     _sockServer.StopServer();
 }