Exemple #1
0
        public void Disconnect()
        {
            //ServerForm server = new ServerForm();

            if (AcceptSocket != null)
            {
                AcceptSocket.Close();
                AcceptSocket.Dispose();
            }
            if (ConnectSocket != null)
            {
                ConnectSocket.Close();
                ConnectSocket.Dispose();
            }

            /*
             * ServerForm server = new ServerForm();
             *
             * if (server.AcceptSocket != null)
             * {
             *  server.AcceptSocket.Close();
             *  server.AcceptSocket.Dispose();
             * }
             * if (server.ConnectSocket != null)
             * {
             *  server.ConnectSocket.Close();
             *  server.ConnectSocket.Dispose();
             * }
             */
        }
Exemple #2
0
 //清理session
 public void Clear()
 {
     //释放引用,并清理缓存,包括释放协议对象等资源
     PacketProtocol.Clear();
     SessionData.Clear();//清理session数据
     if (ConnectSocket == null)
     {
         return;
     }
     try
     {
         ConnectSocket.Shutdown(SocketShutdown.Both);
     }
     catch (Exception e)
     {
         //日志记录
         loger.Fatal(string.Format("CloseClientSocket Disconnect client {0} error, message: {1}", ConnectSocket, e.Message));
     }
     ConnectSocket.Close();
     ConnectSocket = null;
     Server        = null;
 }
Exemple #3
0
 public void DisConnect()
 {
     if (OnDisConnect != null)
     {
         OnDisConnect(null, this);
     }
     //释放引用,并清理缓存,包括释放协议对象等资源
     PacketProtocol.Clear();
     if (ConnectSocket != null)
     {
         try
         {
             ConnectSocket.Shutdown(SocketShutdown.Both);
         }
         catch (Exception e)
         {
             loger.Fatal(e);
         }
     }
     ConnectSocket.Close();
     ConnectSocket = null;
 }