internal Bind_SO( SocketBase baseSocket, AsyncCallback cb, object state) : base(cb, state) { _baseSocket = baseSocket; }
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)"); }
abstract public IAsyncResult BeginBind(SocketBase socket, AsyncCallback callback, object state);
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); } }
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; }
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; }
internal Receive_Op(SocketBase baseSocket) { _baseSocket = baseSocket; }
internal Bind_Op(SocketBase baseSocket, SocketEx primConnSock) { _baseSocket = baseSocket; _primConnSock = primConnSock; }
internal Listen_Op(SocketBase baseSocket, int backlog) { _backlog = backlog; _baseSocket = baseSocket; }
SocketEx _primConnSock; // primary connection (used for socks proxy) // constructor used for async end internal Bind_Op(SocketBase baseSocket) { _baseSocket = baseSocket; _primConnSock = null; }
abstract internal IAsyncResult BeginBind(SocketBase socket, AsyncCallback callback, object state);
abstract internal void Bind(SocketBase socket);
internal ConnectOp( SocketBase baseSocket, string hostName, int hostPort) { _baseSocket = baseSocket; _hostName = hostName; _hostPort = hostPort; }
internal Send_Op(SocketBase baseSocket) { _baseSocket = baseSocket; }
internal ConnectOp(SocketBase baseSocket, EndPoint remoteEP) { _baseSocket = baseSocket; _remoteEP = remoteEP; }
internal Send_Op(SocketBase baseSocket, byte[] buffer, int offset, int size) { _baseSocket = baseSocket; _buffer = buffer; _offset = offset; _size = size; }
internal Accept_Op(SocketBase baseSocket) { this._baseSocket = baseSocket; }
/// <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()"); }
byte[] PrepareBindCmd(SocketBase baseSocket) { return PrepareCmd(baseSocket.RemoteEndPoint, 2); }
/// <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"); }
/* /// <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)"); }
override internal void Bind(SocketBase baseSocket) { CheckDisposed(); IPEndPoint ep = (IPEndPoint)baseSocket.SystemSocket.LocalEndPoint; ep.Port = 0; _socket.Bind(ep); }
internal Accept_Op(SocketBase baseSocket) { _baseSocket = baseSocket; }
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); } }
internal ConnectOp(SocketBase baseSocket) { _baseSocket = baseSocket; }
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; }
abstract public void Bind(SocketBase socket);