/// <summary> /// 断开链接 /// </summary> private void CloseSocket() { _tcpReceiver?.CloseReceiver(); _tcpReceiver = null; if (this.clientSocket != null && this.clientSocket.Connected) { this.clientSocket.Close(); } }
private void OnConnectCallback(IAsyncResult ar) { try { var socket = ar.AsyncState as Socket; Assert.IsNotNull(socket); socket.EndConnect(ar); _tcpReceiver = new TcpProtocol.TcpReceiver(socket, OnRecvCmd, maxTcpPackageSize, OnReceiveError); Debug.Log("connect success"); } catch (Exception e) { OnConnectError(e); } }
/// <summary> /// 断开链接 /// </summary> private void CloseSocket() { _tcpReceiver?.CloseReceiver(); _tcpReceiver = null; if (this.tcpSocket != null && this.tcpSocket.Connected) { this.tcpSocket.Close(); this.tcpSocket = null; } if (null != this.udpRecvThread) { udpRecvThread.Interrupt(); udpRecvThread.Abort(); udpRecvThread = null; } if (this.udpSocket != null && this.udpSocket.Connected) { this.udpSocket.Close(); this.udpSocket = null; } }