Ejemplo n.º 1
0
            /// <summary>
            /// 接收
            /// </summary>
            /// <param name="ar"></param>
            public static void Receive(IAsyncResult ar)
            {
                TextSock self = (TextSock)ar.AsyncState;

                if (self.m_State == SockState.Idle)
                {
                    return;
                }
                int size = 0;

                try
                {
                    size = self.m_Socket.EndReceive(ar);
                }
                catch (SocketException e)
                {
                    if (self.m_Socket.Connected)
                    {
                        self.SetSockError(e.ErrorCode, e.ToString());
                    }
                }
                catch (Exception e)
                {
                    if (self.m_Socket.Connected)
                    {
                        self.SetSockError(0, e.ToString());
                    }
                }
                finally
                {
                }

                self.StopReceive(size);
            }
Ejemplo n.º 2
0
            /// <summary>
            /// 连接
            /// </summary>
            /// <param name="ar"></param>
            public static void Connect(IAsyncResult ar)
            {
                TextSock self = (TextSock)ar.AsyncState;

                if (self.m_State == SockState.Idle)
                {
                    return;
                }
                try
                {
                    self.m_Socket.EndConnect(ar);
                }
                catch (SocketException e)
                {
                    LogSystem.Log("SocketException e");
                    self.SetSockError(e.ErrorCode, e.ToString());
                    self.ConnectFail();
                    return;
                }
                catch (Exception e)
                {
                    LogSystem.Log("Exception e", e.ToString());
                    return;
                }
                self.StopConnect();
            }
Ejemplo n.º 3
0
            /// <summary>
            /// 发送
            /// </summary>
            /// <param name="ar"></param>
            public static void Send(IAsyncResult ar)
            {
                TextSock self = (TextSock)ar.AsyncState;

                if (self.m_State == SockState.Idle)
                {
                    return;
                }
                int size;

                try
                {
                    size = self.m_Socket.EndSend(ar);
                    LogSystem.Log("TextSock EndSend", size);
                }
                catch (SocketException e)
                {
                    self.SetSockError(e.ErrorCode, e.ToString());
                    return;
                }
                catch (Exception)
                {
                    return;
                }
            }
Ejemplo n.º 4
0
            /// <summary>
            /// 断开
            /// </summary>
            /// <param name="ar"></param>
            public static void Disconnect(IAsyncResult ar)
            {
                TextSock self = (TextSock)ar.AsyncState;

                if (self.m_State == SockState.Idle)
                {
                    return;
                }
                try
                {
                    self.m_Socket.EndDisconnect(ar);
                }
                catch (SocketException e)
                {
                    self.SetSockError(e.ErrorCode, e.ToString());
                    return;
                }
                catch (Exception)
                {
                    return;
                }
                self.Disconnect();
            }