Exemple #1
0
        /// <summary>
        ///     Begins an asynchronous request for a connection to a network device.
        /// </summary>
        /// <param name="remoteEP">An EndPoint that represents the remote device.</param>
        /// <param name="callback">The AsyncCallback delegate.</param>
        /// <param name="state">An object that contains state information for this request.</param>
        /// <returns>An IAsyncResult that references the asynchronous connection.</returns>
        /// <exception cref="ArgumentNullException">The remoteEP parameter is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="SocketException">An operating system error occurs while creating the Socket.</exception>
        /// <exception cref="ObjectDisposedException">The Socket has been closed.</exception>
        public new IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
        {
            if (remoteEP == null || callback == null)
            {
                throw new ArgumentNullException();
            }
            if (ProtocolType != ProtocolType.Tcp || ProxyType == ProxyTypes.None || ProxyEndPoint == null)
            {
                return(base.BeginConnect(remoteEP, callback, state));
            }
            else
            {
                CallBack = callback;
                if (ProxyType == ProxyTypes.Socks4)
                {
                    AsyncResult = new Socks4Handler(this, ProxyUser).BeginNegotiate((IPEndPoint)remoteEP,
                                                                                    OnHandShakeComplete,
                                                                                    ProxyEndPoint);
                    return(AsyncResult);
                }
                else if (ProxyType == ProxyTypes.Socks5)
                {
                    AsyncResult = new Socks5Handler(this, ProxyUser, ProxyPass).BeginNegotiate((IPEndPoint)remoteEP,
                                                                                               OnHandShakeComplete,
                                                                                               ProxyEndPoint);
                    return(AsyncResult);
                }

                return(null);
            }
        }
Exemple #2
0
        public new IAsyncResult BeginConnect(string host, int port, AsyncCallback callback, object state)
        {
            if (host == null || callback == null)
            {
                throw new ArgumentNullException();
            }

            if (port <= 0 || port > 65535)
            {
                throw new ArgumentException();
            }

            CallBack = callback;
            if (ProtocolType != ProtocolType.Tcp || ProxyType == ProxyTypes.None || ProxyEndPoint == null)
            {
                RemotePort  = port;
                AsyncResult = BeginDns(host, new HandShakeComplete(OnHandShakeComplete));
                return(AsyncResult);
            }
            else
            {
                if (ProxyType == ProxyTypes.Socks4)
                {
                    AsyncResult = new Socks4Handler(this, ProxyUser).BeginNegotiate(host, port, new HandShakeComplete(OnHandShakeComplete), ProxyEndPoint);
                    return(AsyncResult);
                }
                else if (ProxyType == ProxyTypes.Socks5)
                {
                    AsyncResult = new Socks5Handler(this, ProxyUser, ProxyPass).BeginNegotiate(host, port, new HandShakeComplete(OnHandShakeComplete), ProxyEndPoint);
                    return(AsyncResult);
                }
                return(null);
            }
        }