예제 #1
0
 /// <summary>
 /// 断开链接
 /// </summary>
 private void CloseSocket()
 {
     _tcpReceiver?.CloseReceiver();
     _tcpReceiver = null;
     if (this.clientSocket != null && this.clientSocket.Connected)
     {
         this.clientSocket.Close();
     }
 }
예제 #2
0
        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);
            }
        }
예제 #3
0
        /// <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;
            }
        }