public void Connect() { if (Connected) { return; } Logger.Debug("ClientSocket.Connect({0}, {1});", hostIp, hostPort); try { Socket.Connect(hostIp, hostPort); } catch (Exception e) { Logger.Error("ClientNetwork BeginReceive throw exp:{0}", e); defferedConnected = new ConnectAsyncResult() { Ex = e, }; return; } defferedConnected = new ConnectAsyncResult() { Conn = new Connection(Socket, 0), }; }
public void OneLoop() { try { if (defferedConnected != null) { connection = defferedConnected.Conn; connection.BeginReceive(); // notify if (OnConnected != null) { OnConnected(defferedConnected.Conn, defferedConnected.Ex); } defferedConnected = null; } RefreshMessageQueue(); RefreshClient(); } catch (Exception e) { Logger.Error(e); } }