Summary description for SocketBase.
상속: BytesRoad.Net.Sockets.Advanced.AsyncBase, IDisposable
예제 #1
0
 internal Bind_SO(
     SocketBase baseSocket,
     AsyncCallback cb, 
     object state) : base(cb, state)
 {
     _baseSocket = baseSocket;
 }
예제 #2
0
 public SocketEx(BytesRoad.Net.Sockets.ProxyType proxyType, string proxyServer, int proxyPort, byte[] proxyUser, byte[] proxyPassword)
 {
     this._opState        = OpState.Finished;
     this._recvTimeout    = -1;
     this._sendTimeout    = -1;
     this._acceptTimeout  = -1;
     this._connectTimeout = -1;
     NSTrace.WriteLineVerbose("-> SocketEx(full)");
     if (proxyType == BytesRoad.Net.Sockets.ProxyType.None)
     {
         this._baseSocket = new Socket_None();
     }
     else if (BytesRoad.Net.Sockets.ProxyType.Socks4 == proxyType)
     {
         this._baseSocket = new Socket_Socks4(proxyServer, proxyPort, proxyUser);
     }
     else if (BytesRoad.Net.Sockets.ProxyType.Socks4a == proxyType)
     {
         this._baseSocket = new Socket_Socks4a(proxyServer, proxyPort, proxyUser);
     }
     else if (BytesRoad.Net.Sockets.ProxyType.Socks5 == proxyType)
     {
         this._baseSocket = new Socket_Socks5(proxyServer, proxyPort, proxyUser, proxyPassword);
     }
     else if (BytesRoad.Net.Sockets.ProxyType.HttpConnect == proxyType)
     {
         this._baseSocket = new Socket_HttpConnect(proxyServer, proxyPort, proxyUser, proxyPassword);
     }
     else
     {
         string message = string.Format("Proxy type is not supported ({0}).", proxyType.ToString());
         NSTrace.WriteLineError("EX: " + message + " " + Environment.StackTrace);
         throw new NotSupportedException(message);
     }
     this.Init();
     NSTrace.WriteLineVerbose("<- SocketEx(full)");
 }
예제 #3
0
 abstract public IAsyncResult BeginBind(SocketBase socket, AsyncCallback callback, object state);
예제 #4
0
        override internal void Bind(SocketBase socket)
        {
            CheckDisposed();
            SetProgress(true);
            try
            {
                //-----------------------------------------
                // Get end point for the proxy server
                //
                IPHostEntry host = GetHostByName(_proxyServer);
                if(host == null)
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);

                    // throw new HostNotFoundException("Unable to resolve proxy host name.");

                IPEndPoint proxyEndPoint = ConstructEndPoint(host, _proxyPort);

                //-----------------------------------------
                // Connect to proxy server
                //
                _socket.Connect(proxyEndPoint);

                //-----------------------------------------
                // Send BIND command
                //
                byte[] cmd = PrepareBindCmd((Socket_Socks4a)socket);
                NStream.Write(cmd, 0, cmd.Length);

                //-----------------------------------------
                // Read the response from the proxy server. 
                //
                int read = 0;
                while(read < 8)
                {
                    read += NStream.Read(
                        _response, 
                        read, 
                        _response.Length - read);
                }

                VerifyResponse();
                _localEndPoint = ConstructBindEndPoint(proxyEndPoint.Address);
            
                // remote end point doesn't provided for BIND command
                _remoteEndPoint = null;
            }
            finally
            {
                SetProgress(false);
            }
        }
예제 #5
0
		override internal IAsyncResult BeginBind(SocketBase baseSocket, 
			AsyncCallback callback, 
			object state)
		{
			CheckDisposed();
			Bind_SO stateObj = new Bind_SO(callback, state);
			try
			{
				IPEndPoint ep = (IPEndPoint)baseSocket.SystemSocket.LocalEndPoint;
				ep.Port = 0;
				_socket.Bind(ep);
			}
			catch(Exception e)
			{
				stateObj.Exception = e;
			}
			stateObj.SetCompleted();
			return stateObj;
		}
		override internal IAsyncResult BeginBind(SocketBase baseSocket, AsyncCallback callback, object state)
		{
			ThrowUnsupportException("BeginBind");
			return null;
		}
예제 #7
0
        override internal IAsyncResult BeginBind(SocketBase baseSocket, 
            AsyncCallback callback, 
            object state)
        {
            CheckDisposed();

            Bind_SO stateObj = null;

            SetProgress(true);
            try
            {
                stateObj = new Bind_SO(baseSocket, callback, state);

                //------------------------------------
                // Get end point for the proxy server
                //
                BeginGetHostByName(_proxyServer,
                    new AsyncCallback(Bind_GetHost_End),
                    stateObj);
            }
            catch(Exception ex)
            {
                SetProgress(false);
                throw ex;
            }
            return stateObj;
        }
예제 #8
0
 internal Receive_Op(SocketBase baseSocket)
 {
     _baseSocket = baseSocket;
 }
예제 #9
0
 internal Bind_Op(SocketBase baseSocket, SocketEx primConnSock)
 {
     _baseSocket = baseSocket;
     _primConnSock = primConnSock;
 }
예제 #10
0
 internal Listen_Op(SocketBase baseSocket, int backlog)
 {
     _backlog = backlog;
     _baseSocket = baseSocket;
 }
예제 #11
0
            SocketEx   _primConnSock; // primary connection (used for socks proxy)

            // constructor used for async end
            internal Bind_Op(SocketBase baseSocket)
            {
                _baseSocket = baseSocket;
                _primConnSock = null;
            }
예제 #12
0
		abstract internal IAsyncResult BeginBind(SocketBase socket, AsyncCallback callback, object state);
예제 #13
0
		abstract internal void Bind(SocketBase socket);
예제 #14
0
 internal ConnectOp(
     SocketBase baseSocket, 
     string hostName, 
     int hostPort)
 {
     _baseSocket = baseSocket;
     _hostName = hostName;
     _hostPort = hostPort;
 }
예제 #15
0
 internal Send_Op(SocketBase baseSocket)
 {
     _baseSocket = baseSocket;
 }
예제 #16
0
 internal ConnectOp(SocketBase baseSocket, EndPoint remoteEP)
 {
     _baseSocket = baseSocket;
     _remoteEP = remoteEP;
 }
예제 #17
0
 internal Send_Op(SocketBase baseSocket, byte[] buffer,
     int offset, int size)
 {
     _baseSocket = baseSocket;
     _buffer = buffer;
     _offset = offset;
     _size = size;
 }
예제 #18
0
 internal Accept_Op(SocketBase baseSocket)
 {
     this._baseSocket = baseSocket;
 }
예제 #19
0
        /// <summary>
        /// Initializes  new instance of the 
        /// <see cref="BytesRoad.Net.Sockets.SocketEx"/> class for 
        /// direct connection.
        /// </summary>
        /// <remarks>
        /// With this constructor the instance of the 
        /// <see cref="BytesRoad.Net.Sockets.SocketEx"/> class would
        /// be connected to remote host directly. 
        /// To force connection through the proxy server you need to use
        /// other constructor.
        /// </remarks>
        public SocketEx()
        {
            NSTrace.WriteLineVerbose("-> SocketEx()");

            _baseSocket = new Socket_None();
            Init();

            NSTrace.WriteLineVerbose("<- SocketEx()");
        }
예제 #20
0
 byte[] PrepareBindCmd(SocketBase baseSocket)
 {
     return PrepareCmd(baseSocket.RemoteEndPoint, 2);
 }
예제 #21
0
        /// <summary>
        /// Initializes  new instance of the 
        /// <see cref="BytesRoad.Net.Sockets.SocketEx"/> class for 
        /// direct connection or connection through the proxy servers.
        /// </summary>
        /// <param name="proxyType">
        /// Specifies the type of the proxy server to 
        /// be used for communication with remote end point. 
        /// One of the <see cref="BytesRoad.Net.Sockets.ProxyType"/> values.
        /// </param>
        /// <param name="proxyServer">The host name of the proxy server.</param>
        /// <param name="proxyPort">The port number of the proxy server.</param>
        /// <param name="proxyUser">
        /// The user name which would be used with proxy server 
        /// in authentication procedure.
        /// </param>
        /// <param name="proxyPassword">
        /// The password which would be used with proxy server 
        /// in authentication procedure.
        /// </param>
        /// <remarks>
        ///  If proxy server doesn't support anonymous users and the <i>proxyUser</i>
        ///  parameter equals to <b>null</b> (<b>Nothing</b> in Visual Basic) then the 
        /// <see cref="BytesRoad.Net.Sockets.SocketEx.Connect"/>
        /// method will fail.
        /// </remarks>
        public SocketEx(
            ProxyType proxyType, 
            string proxyServer, 
            int proxyPort,
            byte[] proxyUser,
            byte[] proxyPassword)
        {
            NSTrace.WriteLineVerbose("-> SocketEx(full)");

            if(ProxyType.None == proxyType)
                _baseSocket = new Socket_None();
            else if(ProxyType.Socks4 == proxyType)
                _baseSocket = new Socket_Socks4(proxyServer, proxyPort, proxyUser);
            else if(ProxyType.Socks4a == proxyType)
                _baseSocket = new Socket_Socks4a(proxyServer, proxyPort, proxyUser);
            else if(ProxyType.Socks5 == proxyType)
                _baseSocket = new Socket_Socks5(proxyServer, proxyPort, proxyUser, proxyPassword);
            else if(ProxyType.HttpConnect == proxyType)
                _baseSocket = new Socket_HttpConnect(proxyServer, proxyPort, proxyUser, proxyPassword);
            else
            {
                string msg = string.Format("Proxy type is not supported ({0}).", proxyType.ToString());
                NSTrace.WriteLineError("EX: " + msg + " " + Environment.StackTrace);
                throw new NotSupportedException(msg);
            }

            Init();

            NSTrace.WriteLineVerbose("<- SocketEx(full)");
        }
		override internal void Bind(SocketBase baseSocket)
		{
			ThrowUnsupportException("Bind");
		}
예제 #23
0
        /*
        /// <summary>
        /// Initializes new, bindable instance of the 
        /// <see cref="BytesRoad.Net.Sockets.SocketEx"/> class for 
        /// connection through the proxy servers.
        /// </summary>
        /// <param name="baseSocket">
        /// Instance of the <b>SocketEx</b> class which already connected 
        /// to the remote end point through the proxy server.
        /// </param>
        /// <remarks>
        /// You need to use this constructor if you plan to call
        /// <see cref="BytesRoad.Net.Sockets.SocketEx.Bind"/>
        /// method to listen for incoming connection from the
        /// remote end point. See <see cref="BytesRoad.Net.Sockets.SocketEx.Bind"/>
        /// command for more details. Bind command supported only by the following 
        /// type of proxy servers: <b>Socks4</b>, <b>Socks4a</b>, <b>Socks5</b>.
        /// </remarks>
        public SocketEx(SocketEx baseSocket)
        {
            NSTrace.WriteLineVerbose("-> SocketEx(handle)");
            if(null == baseSocket)
            {
                NSTrace.WriteLineError("EX: SocketEx(handle), handle == null. " + Environment.StackTrace);
                throw new ArgumentNullException("baseSocket");
            }

            _baseSocket = baseSocket._baseSocket;
            Init();

            NSTrace.WriteLineVerbose("<- SocketEx(handle)");
        }
*/
#endregion

        /// <summary>
        /// Used in Accept methods
        /// </summary>
        /// <param name="baseSocket"></param>
        internal SocketEx(SocketBase baseSocket)
        {
            NSTrace.WriteLineVerbose("-> SocketEx(handle)");
            if(null == baseSocket)
            {
                NSTrace.WriteLineError("EX: SocketEx(handle), handle == null. " + Environment.StackTrace);
                throw new ArgumentNullException("baseSocket");
            }

            _baseSocket = baseSocket;
            Init();

            NSTrace.WriteLineVerbose("<- SocketEx(handle)");
        }
예제 #24
0
		override internal void Bind(SocketBase baseSocket)
		{
			CheckDisposed();
			IPEndPoint ep = (IPEndPoint)baseSocket.SystemSocket.LocalEndPoint;
			ep.Port = 0;
			_socket.Bind(ep);
		}
예제 #25
0
 internal Accept_Op(SocketBase baseSocket)
 {
     _baseSocket = baseSocket;
 }
예제 #26
0
        override internal void Bind(SocketBase socket)
        {
            CheckDisposed();
            SetProgress(true);
            try
            {
                //-----------------------------------------
                // Get end point for the proxy server
                //
                IPHostEntry host = GetHostByName(_proxyServer);
                if(host == null)
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                    //throw new HostNotFoundException("Unable to resolve proxy host name.");

                IPEndPoint proxyEndPoint = ConstructEndPoint(host, _proxyPort);

                //-----------------------------------------
                // Connect to proxy server
                //
                _socket.Connect(proxyEndPoint);

                //------------------------------------------
                // Negotiate user
                Negotiate();

                //-----------------------------------------
                // Send BIND command
                //
                byte[] cmd = PrepareBindCmd((Socket_Socks5)socket);
                NStream.Write(cmd, 0, cmd.Length);

                //-----------------------------------------
                // Read the reply from the proxy server. 
                byte[] reply = ReadVerifyReply();
                _localEndPoint = ExtractReplyAddr(reply);

                //remote end point is unknown till accept
                _remoteEndPoint = null;
            }
            finally
            {
                SetProgress(false);
            }
        }
예제 #27
0
 internal ConnectOp(SocketBase baseSocket)
 {
     _baseSocket = baseSocket;
 }
예제 #28
0
        override internal IAsyncResult BeginBind(
            SocketBase baseSocket, 
            AsyncCallback callback, 
            object state)
        {
            CheckDisposed();

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

            Bind_SO stateObj = null;
            SetProgress(true);
            try
            {
                stateObj = new Bind_SO((Socket_Socks4a)baseSocket, callback, state);

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

            return stateObj;
        }
예제 #29
0
 abstract public void Bind(SocketBase socket);