This class is a
CAsyncSocket derived class. With this class, you can connect through SOCKS4/5 and HTTP 1.1 proxies. This class works as semi-transparent layer between your own class and
CAsyncSocket. This class is used in FileZilla, a powerful open-source FTP client. It can be found here. For more information about SOCKS4/5, go here. For more information about HTTP 1.1, go here and search for RFC2616 and RFC2617.
How to use?
If you are using
, you don't have to change much in your already existing code to use
. To use it, you've to derive your own class from
, and you've to provide a definition for
OnListenFinished(unsigned long &retProxyIp,int &retProxyPort)
. When you create an instance of your derived class, you should call
. If you overload the
functions in your derived class, you have to call
as first instruction in your
If an operation fails,
OnProxyOperationFailed is called. There you can handle the error.
int nOpID specifies the type of the operation that failed:
PROXYOP_CONNECT when a connection attempt failed and
PROXYOP_LISTEN when creating a listen socket failed.
If you want to use
CAsyncProxySocket to create a listen socket, you have to use this overloaded function:
virtual BOOL Listen(unsigned long serverIp).
serverIP is the IP of the server you are already connected through the SOCKS proxy. You can't use listen sockets over a SOCKS proxy without a primary connection. Listen sockets are only supported by SOCKS proxies, this won't work with HTTP proxies. When the listen socket is created successfully,
OnListenFinished is called. The parameters
unsigned long &retProxyIp and
int &retProxyPort will tell you the IP and the port of the listen socket. After that, you have to handle the
OnAccept message and accept the connection.
Description of the other new functions and their parameters
void SetProxy(int nProxyType);
void SetProxy(int nProxyType, CString ProxyHost, int nProxyPort);
void SetProxy(int nProxyType, CString ProxyHost, int nProxyPort,CString
ProxyUser, CString ProxyPass);
Call one of these functions to set the proxy type. Parameters:
nProxyType specifies the Proxy Type.
nProxyPort specify the address of the proxy.
ProxyPass are only available for SOCKS5 proxies.
Supported proxy types:
GetProxyPeerName is like
CAsyncSocket, but returns the address of the server connected through the proxy. If using proxies,
GetPeerName only returns the address of the proxy.
Returns the used proxy type.
const int GetLastProxyError() const;
Returns the last proxy error.
- 20 Dec 2001
- Added basic HTTP 1.1 authentication.
- Fixed memory leak in SOCKS5 code.
OnSocksOperationFailed will be called after Socket has been closed.
- Fixed some minor bugs.
- 9 Dec 2001