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(); * } */ }
//清理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; }
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; }