/// <summary> /// Establishes a connection to a remote device. /// </summary> /// <param name="host">The remote host to connect to.</param> /// <param name="port">The remote port to connect to.</param> /// <exception cref="ArgumentNullException">The host parameter is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException">The port parameter is invalid.</exception> /// <exception cref="SocketException">An operating system error occurs while accessing the Socket.</exception> /// <exception cref="ObjectDisposedException">The Socket has been closed.</exception> /// <exception cref="ProxyException">An error occured while talking to the proxy server.</exception> /// <remarks>If you use this method with a SOCKS4 server, it will let the server resolve the hostname. Not all SOCKS4 servers support this 'remote DNS' though.</remarks> public new void Connect(string host, int port) { if (host == null) { throw new ArgumentNullException("host"); } if (port <= 0 || port > 65535) { throw new ArgumentException("Invalid port."); } if (this.ProtocolType != ProtocolType.Tcp || ProxyType == ProxyTypes.None || (ProxyEndPoint == null && ProxyType != ProxyTypes.LocalUdp)) { base.Connect(new IPEndPoint(Dns.GetHostEntry(host).AddressList[0], port)); } else { if (ProxyType != ProxyTypes.LocalUdp) { base.Connect(ProxyEndPoint); } if (ProxyType == ProxyTypes.Socks4) { (socksHandler = new Socks4Handler(this, ProxyUser)).Negotiate(host, port); } else if (ProxyType == ProxyTypes.Socks5) { (socksHandler = new Socks5Handler(this, ProxyUser, ProxyPass)).Negotiate(host, port); } #if USEUDP else if (ProxyType == ProxyTypes.Socks5Udp) { (socksHandler = new Socks5UdpHandler(this, ProxyUser, ProxyPass)).Negotiate(host, port); } else if (ProxyType == ProxyTypes.LocalUdp) { socksHandler = new LocalUdpHandler(); } #endif } }
/// <summary> /// Establishes a connection to a remote device. /// </summary> /// <param name="remoteEP">An EndPoint that represents the remote device.</param> /// <exception cref="ArgumentNullException">The remoteEP parameter is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="SocketException">An operating system error occurs while accessing the Socket.</exception> /// <exception cref="ObjectDisposedException">The Socket has been closed.</exception> /// <exception cref="ProxyException">An error occured while talking to the proxy server.</exception> public new void Connect(EndPoint remoteEP) { if (remoteEP == null) { throw new ArgumentNullException("remoteEP"); } if (this.ProtocolType != ProtocolType.Tcp || ProxyType == ProxyTypes.None || (ProxyEndPoint == null && ProxyType != ProxyTypes.LocalUdp)) { base.Connect(remoteEP); } else { if (ProxyType != ProxyTypes.LocalUdp) { base.Connect(ProxyEndPoint); } if (ProxyType == ProxyTypes.Socks4) { (socksHandler = new Socks4Handler(this, ProxyUser)).Negotiate((IPEndPoint)remoteEP); } else if (ProxyType == ProxyTypes.Socks5) { (socksHandler = new Socks5Handler(this, ProxyUser, ProxyPass)).Negotiate((IPEndPoint)remoteEP); } #if USEUDP else if (ProxyType == ProxyTypes.Socks5Udp) { (socksHandler = new Socks5UdpHandler(this, ProxyUser, ProxyPass)).Negotiate((IPEndPoint)remoteEP); } else if (ProxyType == ProxyTypes.LocalUdp) { socksHandler = new LocalUdpHandler(); } #endif } }