Example #1
0
        /// <summary>
        /// Close a connection.
        /// </summary>
        /// <param name="pClient">Connection to close</param>
        public void KillClient(TcpClient pClient)
        {
            try
            {
                TcpConnectionHandle cnxHandle = TcpConnectionHandler.GetConnectionHandle(pClient);

                if (cnxHandle != null)
                {
                    OnCloseMessageReceived(new MessageData(null, 0, pClient.Client.RemoteEndPoint, cnxHandle));
                    cnxHandle.ConnectionClient.Client.Shutdown(SocketShutdown.Both);
                    cnxHandle.ConnectionClient.Client.Close();
                    cnxHandle.ConnectionClient.Close();
                    // Kill the thread.
                    cnxHandle.ConnectionThread.Join(50);
                    lock (TcpConnectionHandler)
                    {
                        TcpConnectionHandler.Remove(cnxHandle);
                    }
                    cnxHandle = null;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception raised killing tcpclient connection client.", ex);
            }
        }