public IAsyncResult BeginConnect(IPEndPoint remoteEP, AsyncCallback callback, object state) { var client = _client; Debug.WriteLine("Client BeginConnect ({0})", remoteEP); CheckDisposed(); client.AddressClientConnectedTo = remoteEP.Address.ToString(); client.PortNumber = remoteEP.Port; var scir = new SocketClientConnectAsyncResult { AsyncState = state }; var result = client.ConnectToServerAsync(AsyncConnectComplete, new AsyncConnectState(scir, callback)); if (result != SocketErrorCodes.SOCKET_OK && result != SocketErrorCodes.SOCKET_OPERATION_PENDING) { throw new SocketException(result.ToError()); } return(scir); }
public AsyncConnectState(SocketClientConnectAsyncResult asyncResult, AsyncCallback asyncCallback) { AsyncResult = asyncResult; AsyncCallback = asyncCallback; }