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