Example #1
0
        /// <summary>
        /// Establishes a connection to a remote host. The host is specified by an IP address and a port number.
        /// </summary>
        /// <param name="host">The IP address of the remote host.</param>
        /// <param name="port">The port number of the remote host.</param>
        public new void Connect(string host, int port)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            if (port <= 0 || port > 65535)
            {
                throw new ArgumentOutOfRangeException("port", "port must be greater than zero and less than 65535");
            }

            if (this.ProtocolType != ProtocolType.Tcp || this.ProxyType == ProxyType.None || this.ProxyEndPoint == null)
            {
                base.Connect(host, port);
            }
            else
            {
                base.Connect(this.ProxyEndPoint);
                ProxyBase proxy = null;
                if (this.ProxyType == ProxyType.Socks4)
                {
                    proxy = new Socks4Proxy(this, this.ProxyUsername);
                }
                else if (this.ProxyType == ProxyType.Socks4a)
                {
                    proxy = new Socks4AProxy(this, this.ProxyUsername);
                }
                else if (this.ProxyType == ProxyType.Socks5)
                {
                    proxy = new Socks5Proxy(this, this.ProxyUsername, this.ProxyPassword);
                }

                if (proxy != null)
                {
                    proxy.Connect(host, port);
                }
            }
        }
Example #2
0
		/// <summary>
		/// Establishes a connection to a remote host. The host is specified by an IP address and a port number.
		/// </summary>
		/// <param name="host">The IP address of the remote host.</param>
		/// <param name="port">The port number of the remote host.</param>
		public new void Connect(string host, int port) {
			if(host == null) {
				throw new ArgumentNullException("host");
			}

			if(port <= 0 || port > 65535) {
				throw new ArgumentOutOfRangeException("port", "port must be greater than zero and less than 65535");
			}

			if(this.ProtocolType != ProtocolType.Tcp || this.ProxyType == ProxyType.None || this.ProxyEndPoint == null) {
				base.Connect(host, port);
			}
			else {
				base.Connect(this.ProxyEndPoint);
				ProxyBase proxy = null;
				if(this.ProxyType == ProxyType.Socks4) {
					proxy = new Socks4Proxy(this, this.ProxyUsername);
				}
				else if(this.ProxyType == ProxyType.Socks4a) {
					proxy = new Socks4AProxy(this, this.ProxyUsername);
				}
				else if(this.ProxyType == ProxyType.Socks5) {
					proxy = new Socks5Proxy(this, this.ProxyUsername, this.ProxyPassword);
				}

				if(proxy != null) {
					proxy.Connect(host, port);
				}
			}
		}