コード例 #1
0
        override internal IAsyncResult BeginConnect(
            EndPoint remoteEP,
            AsyncCallback callback,
            object state)
        {
            CheckDisposed();
            Connect_SO stateObj = null;

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(-1, callback, state);

                _socket.BeginConnect(
                    remoteEP,
                    new AsyncCallback(Connect_End),
                    stateObj);
            }
            catch (Exception e)
            {
                SetProgress(false);
                throw e;
            }

            return(stateObj);
        }
コード例 #2
0
        void Connect_Write_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                NStream.EndWrite(ar);

                //------------------------------------
                // Read the response from proxy server.
                //
                NStream.BeginRead(
                    _response,
                    0,
                    8,
                    new AsyncCallback(Connect_Read_End),
                    stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #3
0
        void GetHost_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry host = Dns.EndGetHostByName(ar);
                if (null == host)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve host name.");

                EndPoint remoteEP = SocketBase.ConstructEndPoint(host, stateObj.Port);
                _socket.BeginConnect(remoteEP,
                                     new AsyncCallback(Connect_End),
                                     stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #4
0
ファイル: Socket_Socks4.cs プロジェクト: kineva1992/repos
        void Connect_Read_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                int num = NStream.EndRead(ar);
                stateObj.ReadBytes += num;

                if (stateObj.ReadBytes < 8)
                {
                    //------------------------------------
                    // Read the response from proxy server.
                    //
                    NStream.BeginRead(_response,
                                      stateObj.ReadBytes,
                                      8 - stateObj.ReadBytes,
                                      new AsyncCallback(Connect_Read_End),
                                      stateObj);
                }
                else
                {
                    VerifyResponse();
                    stateObj.SetCompleted();
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #5
0
ファイル: Socket_Socks4.cs プロジェクト: kineva1992/repos
        void Connect_Connect_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _socket.EndConnect(ar);

                _localEndPoint  = null;
                _remoteEndPoint = stateObj.RemoteEndPoint;

                //------------------------------------
                // Send CONNECT command
                //
                byte[] cmd = PrepareConnectCmd(stateObj.RemoteEndPoint);

                NStream.BeginWrite(cmd,
                                   0,
                                   cmd.Length,
                                   new AsyncCallback(Connect_Write_End),
                                   stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #6
0
        internal override IAsyncResult BeginConnect(string hostName, int hostPort, AsyncCallback callback, object state)
        {
            base.CheckDisposed();
            if (hostName == null)
            {
                throw new ArgumentNullException("hostName", "The value cannot be null.");
            }
            if ((hostPort < 0) || (hostPort > 0xffff))
            {
                throw new ArgumentOutOfRangeException("hostPort", "Value, specified for the port is out of the valid range.");
            }
            Connect_SO t_so = null;

            this.SetProgress(true);
            try
            {
                t_so = new Connect_SO(null, hostName, hostPort, callback, state);
                if (this._resolveHostEnabled)
                {
                    SocketBase.BeginGetHostByName(hostName, new AsyncCallback(this.Connect_GetHost_Host_End), t_so);
                    return(t_so);
                }
                SocketBase.BeginGetHostByName(base._proxyServer, new AsyncCallback(this.Connect_GetHost_Proxy_End), t_so);
            }
            catch (Exception exception)
            {
                this.SetProgress(false);
                throw exception;
            }
            return(t_so);
        }
コード例 #7
0
ファイル: Socket_Socks4.cs プロジェクト: kineva1992/repos
        void Connect_GetHost_Host_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry host = EndGetHostByName(ar);
                if (null == host)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve host name.");

                stateObj.RemoteEndPoint = SocketBase.ConstructEndPoint(host, stateObj.Port);

                //------------------------------------
                // Get end point for the proxy server
                //
                BeginGetHostByName(_proxyServer,
                                   new AsyncCallback(this.Connect_GetHost_Proxy_End),
                                   stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #8
0
ファイル: Socket_Socks4.cs プロジェクト: kineva1992/repos
        override internal IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
        {
            CheckDisposed();

            Connect_SO stateObj = null;

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(remoteEP, -1, callback, state);

                //------------------------------------
                // Get end point for the proxy server
                //
                BeginGetHostByName(_proxyServer,
                                   new AsyncCallback(this.Connect_GetHost_Proxy_End),
                                   stateObj);
            }
            catch (Exception ex)
            {
                SetProgress(false);
                throw ex;
            }
            return(stateObj);
        }
コード例 #9
0
        void Connect_GetPrxHost_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry proxyEntry = EndGetHostByName(ar);
                if (null == proxyEntry)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve proxy name.");

                IPEndPoint proxyEndPoint = ConstructEndPoint(proxyEntry, _proxyPort);

                //------------------------------------------
                // Connect to proxy server
                _socket.BeginConnect(proxyEndPoint,
                                     new AsyncCallback(Connect_Connect_End),
                                     stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #10
0
        void Connect_GetHost_Host_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry host = EndGetHostByName(ar);
                if (null != host)
                {
                    stateObj.RemoteEndPoint = ConstructEndPoint(host, stateObj.HostPort);
                }

                //------------------------------------
                // Get end point for the proxy server
                //
                BeginGetHostByName(_proxyServer,
                                   new AsyncCallback(Connect_GetHost_Proxy_End),
                                   stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #11
0
        override internal IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
        {
            CheckDisposed();
            if (null == remoteEP)
            {
                throw new ArgumentNullException("remoteEP", "The value cannot be null.");
            }

            Connect_SO stateObj = null;

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(remoteEP, null, -1, callback, state);

                //------------------------------------
                // Get end point for the proxy server
                //
                BeginGetHostByName(_proxyServer,
                                   new AsyncCallback(Connect_GetHost_Proxy_End),
                                   stateObj);
            }
            catch (Exception ex)
            {
                SetProgress(false);
                throw ex;
            }
            return(stateObj);
        }
コード例 #12
0
        override internal IAsyncResult BeginConnect(
            string hostName,
            int port,
            AsyncCallback callback,
            object state)
        {
            CheckDisposed();
            Connect_SO stateObj = null;

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(null, port, callback, state);
                BeginGetHostByName(
                    hostName,
                    new AsyncCallback(Connect_GetHost_Host_End),
                    stateObj);
            }
            catch (Exception e)
            {
                SetProgress(false);
                throw e;
            }

            return(stateObj);
        }
コード例 #13
0
        private void Connect_ReadReply_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                ByteVector reply  = this.EndReadReply(ar);
                string     reason = null;
                int        num    = this.AnalyzeReply(reply, out reason);
                if ((num < 200) || (num > 0x12b))
                {
                    if (((0x197 != num) || asyncState.UseCredentials) || (base._proxyUser == null))
                    {
                        throw new SocketException(0x274d);
                    }
                    asyncState.UseCredentials = true;
                    byte[] buffer = this.GetConnectCmd(asyncState.HostName, asyncState.HostPort, asyncState.UseCredentials);
                    base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Connect_Write_End), asyncState);
                }
                else
                {
                    asyncState.SetCompleted();
                }
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
コード例 #14
0
        void Connect_Connect_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _socket.EndConnect(ar);

                //------------------------------------------
                // Send CONNECT command
                byte[] cmd = GetConnectCmd(stateObj.HostName,
                                           stateObj.HostPort,
                                           stateObj.UseCredentials);

                NStream.BeginWrite(cmd, 0, cmd.Length,
                                   new AsyncCallback(Connect_Write_End),
                                   stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #15
0
        private void Connect_Read_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                int num = base.NStream.EndRead(ar);
                asyncState.ReadBytes += num;
                if (asyncState.ReadBytes < 8)
                {
                    base.NStream.BeginRead(this._response, asyncState.ReadBytes, 8 - asyncState.ReadBytes, new AsyncCallback(this.Connect_Read_End), asyncState);
                }
                else
                {
                    this.VerifyResponse();
                    if (asyncState.RemoteEndPoint == null)
                    {
                        this._remotePort = asyncState.HostPort;
                        this._remoteHost = asyncState.HostName;
                    }
                    asyncState.SetCompleted();
                }
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
コード例 #16
0
        void Connect_ReadReply_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                ByteVector reply = EndReadReply(ar);

                //------------------------------------------
                // Analyze reply
                string reason = null;
                int    code   = AnalyzeReply(reply, out reason);

                //------------------------------------------
                // is good return code?
                if (code >= 200 && code <= 299)
                {
                    stateObj.SetCompleted();
                }
                else if ((407 == code) &&
                         !(stateObj.UseCredentials) &&
                         (_proxyUser != null))
                {
                    //------------------------------------------
                    // If Proxy Authentication Required
                    // but we do not issued it, then try again

                    stateObj.UseCredentials = true;

                    //------------------------------------------
                    // Send CONNECT command
                    byte[] cmd = GetConnectCmd(
                        stateObj.HostName,
                        stateObj.HostPort,
                        stateObj.UseCredentials);

                    NStream.BeginWrite(cmd, 0, cmd.Length,
                                       new AsyncCallback(Connect_Write_End),
                                       stateObj);
                }
                else
                {
                    // string msg = string.Format("Connection refused by web proxy: {0} ({1}).", reason, code);
                    // throw new ProxyErrorException(msg);
                    throw new SocketException(SockErrors.WSAECONNREFUSED);
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #17
0
        void OnEndConnectCB(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _socket.EndConnect(ar);
                _reader.BeginReadResponse(stateObj.Timeout,
                                          new AsyncCallback(this.OnResponse),
                                          stateObj);
            }
            catch (SocketException e)
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else if (e.ErrorCode == SockErrors.WSAETIMEDOUT)
                {
                    stateObj.Exception = GetTimeoutException(e);
                }
                else
                {
                    stateObj.Exception = e;
                }
                stateObj.SetCompleted();
            }
            catch (Exception e)
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else
                {
                    stateObj.Exception = e;
                }
                stateObj.SetCompleted();
            }
            catch
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                    stateObj.SetCompleted();
                }
                else
                {
                    NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                    throw;
                }
            }
        }
コード例 #18
0
        override public IAsyncResult BeginConnect(
            string hostName,
            int hostPort,
            AsyncCallback callback,
            object state)
        {
            CheckDisposed();

            if (null == hostName)
            {
                throw new ArgumentNullException("hostName", "The value cannot be null.");
            }

            if (hostPort < IPEndPoint.MinPort || hostPort > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException("hostPort", "Value, specified for the port is out of the valid range.");
            }

            Connect_SO stateObj = null;

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(null, hostName, hostPort, callback, state);
                if (_resolveHostEnabled)
                {
                    //--------------------------------------
                    // Trying to resolve host name locally
                    BeginGetHostByName(
                        hostName,
                        new AsyncCallback(Connect_GetHost_Host_End),
                        stateObj);
                }
                else
                {
                    //-------------------------------------
                    // Get end point for the proxy server
                    //
                    BeginGetHostByName(
                        _proxyServer,
                        new AsyncCallback(Connect_GetHost_Proxy_End),
                        stateObj);
                }
            }
            catch (Exception e)
            {
                SetProgress(false);
                throw e;
            }

            return(stateObj);
        }
コード例 #19
0
        internal IAsyncResult BeginConnect(int timeout,
                                           string server,
                                           int port,
                                           AsyncCallback cb,
                                           object state)
        {
            CheckDisposed();

            Connect_SO stateObj = null;

            if (null == server)
            {
                throw new ArgumentNullException("server");
            }

            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException("port", "Value, specified for the port is out of valid range.");
            }

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(timeout, cb, state);

                _socket.ConnectTimeout = timeout;
                _socket.BeginConnect(server, port,
                                     new AsyncCallback(this.OnEndConnectCB),
                                     stateObj);
            }
            catch (SocketException e)
            {
                SetProgress(false);
                CheckDisposed();
                CheckTimeoutException(e);
                throw;
            }
            catch (Exception)
            {
                SetProgress(false);
                CheckDisposed();
                throw;
            }
            catch
            {
                SetProgress(false);
                CheckDisposed();
                throw;
            }
            return(stateObj);
        }
コード例 #20
0
        private void Connect_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                base._socket.EndConnect(ar);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
            }
            asyncState.SetCompleted();
        }
コード例 #21
0
        void Connect_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _socket.EndConnect(ar);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
            }
            stateObj.SetCompleted();
        }
コード例 #22
0
        private void Connect_Write_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                base.NStream.EndWrite(ar);
                this.BeginReadVerifyReply(new AsyncCallback(this.Connect_Read_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
コード例 #23
0
        private void Connect_Connect_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                base._socket.EndConnect(ar);
                this.BeginNegotiate(new AsyncCallback(this.Connect_Negotiate_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
コード例 #24
0
        private void Connect_Negotiate_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                this.EndNegotiate(ar);
                byte[] buffer = this.PrepareConnectCmd(asyncState.RemoteEndPoint, asyncState.HostName, asyncState.HostPort);
                base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Connect_Write_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
コード例 #25
0
        private void Connect_Connect_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                base._socket.EndConnect(ar);
                byte[] buffer = this.GetConnectCmd(asyncState.HostName, asyncState.HostPort, asyncState.UseCredentials);
                base.NStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.Connect_Write_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
コード例 #26
0
        void Connect_Read_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                int num = NStream.EndRead(ar);
                stateObj.ReadBytes += num;

                if (stateObj.ReadBytes < 8)
                {
                    //------------------------------------
                    // Read the response from proxy server.
                    //
                    NStream.BeginRead(
                        _response,
                        stateObj.ReadBytes,
                        8 - stateObj.ReadBytes,
                        new AsyncCallback(Connect_Read_End),
                        stateObj);
                }
                else
                {
                    VerifyResponse();

                    //---------------------------------------
                    // I we unable to resolve remote host then
                    // store information - it will required
                    // later for BIND command.
                    if (null == stateObj.RemoteEndPoint)
                    {
                        _remotePort = stateObj.HostPort;
                        _remoteHost = stateObj.HostName;
                    }

                    stateObj.SetCompleted();
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #27
0
        public override IAsyncResult BeginConnect(
            string hostName,
            int hostPort,
            AsyncCallback callback,
            object state)
        {
            Connect_SO stateObj = null;

            CheckDisposed();

            if (null == hostName)
            {
                throw new ArgumentNullException("hostName", "The value cannot be null.");
            }

            if (hostPort < IPEndPoint.MinPort || hostPort > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException("hostPort", "Value, specified for the port is out of the valid range.");
            }

            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(
                    hostName,
                    hostPort,
                    PreAuthenticate,
                    callback,
                    state);

                //------------------------------------
                // Get end point for the proxy server
                BeginGetHostByName(
                    _proxyServer,
                    new AsyncCallback(Connect_GetPrxHost_End),
                    stateObj);
            }
            catch (Exception e)
            {
                SetProgress(false);
                throw e;
            }

            return(stateObj);
        }
コード例 #28
0
        internal override IAsyncResult BeginConnect(string hostName, int port, AsyncCallback callback, object state)
        {
            base.CheckDisposed();
            Connect_SO t_so = null;

            this.SetProgress(true);
            try
            {
                t_so = new Connect_SO(null, port, callback, state);
                SocketBase.BeginGetHostByName(hostName, new AsyncCallback(this.Connect_GetHost_Host_End), t_so);
            }
            catch (Exception exception)
            {
                this.SetProgress(false);
                throw exception;
            }
            return(t_so);
        }
コード例 #29
0
        internal override IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
        {
            base.CheckDisposed();
            Connect_SO t_so = null;

            this.SetProgress(true);
            try
            {
                t_so = new Connect_SO(remoteEP, -1, callback, state);
                SocketBase.BeginGetHostByName(base._proxyServer, new AsyncCallback(this.Connect_GetHost_Proxy_End), t_so);
            }
            catch (Exception exception)
            {
                this.SetProgress(false);
                throw exception;
            }
            return(t_so);
        }
コード例 #30
0
        internal override IAsyncResult BeginConnect(string hostName, int port, AsyncCallback callback, object state)
        {
            base.CheckDisposed();
            this.SetProgress(true);
            Connect_SO stateObject = null;

            try
            {
                stateObject = new Connect_SO(port, callback, state);
                Dns.BeginGetHostEntry(hostName, new AsyncCallback(this.GetHost_End), stateObject);
            }
            catch (Exception exception)
            {
                this.SetProgress(false);
                throw exception;
            }
            return(stateObject);
        }
コード例 #31
0
        override internal IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
        {
            CheckDisposed();
            if(null == remoteEP)
                throw new ArgumentNullException("remoteEP", "The value cannot be null.");

            Connect_SO stateObj = null;
            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(remoteEP, null, -1, callback, state);

                //------------------------------------
                // Get end point for the proxy server
                //
                BeginGetHostByName(
                    _proxyServer,
                    new AsyncCallback(Connect_GetHost_Proxy_End),
                    stateObj);
            }
            catch(Exception ex)
            {
                SetProgress(false);
                throw ex;
            }

            return stateObj;
        }
コード例 #32
0
        override internal IAsyncResult BeginConnect(
            string hostName,
            int hostPort, 
            AsyncCallback callback,
            object state)
        {
            CheckDisposed();

            if(null == hostName)
                throw new ArgumentNullException("hostName", "The value cannot be null.");

            if(hostPort < IPEndPoint.MinPort || hostPort > IPEndPoint.MaxPort)
                throw new ArgumentOutOfRangeException("hostPort", "Value, specified for the port is out of the valid range."); 

            Connect_SO stateObj = null;
            SetProgress(true);
            try
            {
                stateObj = new Connect_SO(null, hostName, hostPort, callback, state);
                if(_resolveHostEnabled)
                {
                    //--------------------------------------
                    // Trying to resolve host name locally
                    BeginGetHostByName(
                        hostName,
                        new AsyncCallback(Connect_GetHost_Host_End),
                        stateObj);
                }
                else
                {
                    //-------------------------------------
                    // Get end point for the proxy server
                    //
                    BeginGetHostByName(
                        _proxyServer,
                        new AsyncCallback(Connect_GetHost_Proxy_End),
                        stateObj);
                }
            }
            catch(Exception e)
            {
                SetProgress(false);
                throw e;
            }

            return stateObj;
        }
コード例 #33
0
		override internal IAsyncResult BeginConnect(string hostName, 
			int port, 
			AsyncCallback callback, 
			object state)
		{
			CheckDisposed();
			SetProgress(true);
			Connect_SO stateObj = null;
			try
			{
				stateObj = new Connect_SO(port, callback, state);
				Dns.BeginGetHostByName(hostName, new AsyncCallback(GetHost_End), stateObj);
			}
			catch(Exception e)
			{
				SetProgress(false);
				throw e;
			}
			return stateObj;
		}
コード例 #34
0
		override internal IAsyncResult BeginConnect(EndPoint remoteEP, 
			AsyncCallback callback, 
			object state)
		{
			CheckDisposed();
			Connect_SO stateObj = null;
			SetProgress(true);
			try
			{
				stateObj = new Connect_SO(-1, callback, state);

				_socket.BeginConnect(remoteEP, 
					new AsyncCallback(Connect_End),
					stateObj);
			}
			catch(Exception e)
			{
				SetProgress(false);
				throw e;
			}
			return stateObj;
		}
コード例 #35
0
		internal override IAsyncResult BeginConnect(string hostName, 
			int hostPort, 
			AsyncCallback callback, 
			object state)
		{
			Connect_SO stateObj = null;
			CheckDisposed();

			if(null == hostName)
				throw new ArgumentNullException("hostName", "The value cannot be null.");

			if(hostPort < IPEndPoint.MinPort || hostPort > IPEndPoint.MaxPort)
				throw new ArgumentOutOfRangeException("hostPort", "Value, specified for the port is out of the valid range."); 

			SetProgress(true);
			try
			{
				stateObj = new Connect_SO(hostName,
					hostPort,
					PreAuthenticate,
					callback,
					state);

				//------------------------------------
				// Get end point for the proxy server
				BeginGetHostByName(_proxyServer, 
					new AsyncCallback(Connect_GetPrxHost_End),
					stateObj);
			}
			catch(Exception e)
			{
				SetProgress(false);
				throw e;
			}
			return stateObj;
		}