public void Conect(string host, int port) { if (mStaus != PEER_STATUS.NONE) { return; } Close(); mClient = new TcpClient(famliy); mStaus = PEER_STATUS.CONNECTING; mClient.BeginConnect(host, port, onBeginConnect, null); }
void Close() { if (null != mClient) { mClient.Close(); } mClient = null; mStaus = PEER_STATUS.NONE; mSendBuff.Clear(); mSendAsy = null; mRecieveAsy = null; mRecieveStream.Close(); }
void onBeginConnect(IAsyncResult ar) { if (null != mClient) { mClient.EndConnect(ar); if (null != mOnConnect) { mOnConnect(mClient.Connected); } if (!mClient.Connected) { Close(); } else { mRecieveStream = new MemoryStream(); mStaus = PEER_STATUS.CONNECTED; } } }
public void Conect(string host, int port) { if (mStaus != PEER_STATUS.NONE) { return; } Close(); mClient = new TcpClient(famliy); mStaus = PEER_STATUS.CONNECTING; try { mClient.BeginConnect(host, port, onBeginConnect, null); } catch (System.Exception e) { Close(); if (null != mOnConnect) { mOnConnect(false); } } }