private void on_begin_connect(IAsyncResult result) { ConnectParas conn_paras = (ConnectParas)result.AsyncState; if (conn_paras == null) { Log.ErrorA("[Net] on_begin_connect ConnectParas = null"); return; } if (conn_paras.ClientSocket == null) { Log.ErrorA("[Net] on_begin_connect ConnectParas.ClientSocket = null"); return; } try { conn_paras.ClientSocket.EndConnect(result); } catch (System.Exception ex) { Log.ErrorAf("[Net] Host={0},Port={1} EndConnect Error={2}", conn_paras.Host, conn_paras.Port, ex.ToString()); return; } conn_paras.Conn.DoAsyncReceive(); }
public bool Connect(string host, UInt32 port, ISession session) { if (session == null) { Log.ErrorAf("[Net] Host={0},Port={1} Connect Session Error", host, port); return(false); } Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); if (socket == null) { Log.ErrorAf("[Net] Host={0},Port={1} Connect Socket Error", host, port); return(false); } IConnection conn = conn_mgr.Create(this, socket, session); if (conn == null) { Log.ErrorAf("[Net] Host={0},Port={1} Connect Connection Error", host, port); return(false); } IPEndPoint connect_endpoint = new IPEndPoint(IPAddress.Parse(host), (int)port); if (connect_endpoint == null) { Log.ErrorAf("[Net] Host={0},Port={1} Connect IPEndPoint Error", host, port); return(false); } ConnectParas conn_paras = new ConnectParas(socket, host, port, conn); if (conn_paras == null) { Log.ErrorAf("[Net] Host={0},Port={1} Connect ConnectParas Error", host, port); return(false); } try { socket.BeginConnect(connect_endpoint, on_begin_connect, conn_paras); } catch (System.Exception ex) { Log.ErrorAf("[Net] Host={0},Port={1} BeginConnect Error={2}", host, port, ex.ToString()); return(false); } return(true); }