public BeginConnect ( |
||
remoteEP | ||
callback | AsyncCallback | |
state | object | |
return | void |
public void BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().FullName);
}
if (Connected)
{
throw new SocketException((int) SocketError.IsConnected);
}
var arg = new SocketAsyncEventArgs();
arg.RemoteEndPoint = remoteEP;
arg.Completed += OnTcpConnectCompleted;
arg.UserToken = new TcpUserToken(callback, state);
Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, arg);
}
public void Start(byte[] firstPacket, int length, Socket socket, int targetPort) { this._firstPacket = firstPacket; this._firstPacketLength = length; this._local = socket; try { EndPoint remoteEP = SocketUtil.GetEndPoint("127.0.0.1", targetPort); // Connect to the remote endpoint. _remote = new WrappedSocket(); _remote.BeginConnect(remoteEP, ConnectCallback, null); } catch (Exception e) { Logging.LogUsefulException(e); this.Close(); } }