一個c++ socket 用戶端庫
<a href="http://www.rudeserver.com/socket/index.html">http://www.rudeserver.com/socket/index.html</a>
The library is currently available for linux development environments.
Features:
Supports Sockes 4, Socks 5, HTTP Proxy
Like all RudeServer Libraries: Simple and Easy to use.
Open Source and Free
Platform Independent Interface
General Usage
<code>Socket *socket = new Socket(); socket->connect("google.com", 80); socket->sends("GET / HTTP/1.0\n\n"); const char *response = socket->reads(); cout << response; socket->close();</code>
SSL Usage
<code>Socket *socket = new Socket(); socket->connectSSL("google.com", 443); socket->sends("GET / HTTP/1.0\n\n"); const char *response = socket->reads(); cout << response; socket->close();</code>
Chaining Connections
<code>Socket *socket = new Socket(); socket->insertSocks4("12.34.56.78", 8000, "username"); socket->insertSocks5("12.34.56.78", 8000, "username", "password"); socket->insertProxy("12.34.56.78", 8080); socket->connectSSL("google.com", 443); socket->sends("GET / HTTP/1.0\n\n"); const char *response = socket->reads(); cout << response; socket->close();</code>
Adding Error checking
<code>Socket *socket = new Socket(); if(socket->connectSSL("google.com", 443)) { if(socket->sends("GET / HTTP/1.0\n\n")) { const char *response = socket->reads(); if(response) { cout << response; } else { cout << socket->getError() << "\n"; } } else { cout << socket->getError() << "\n"; } socket->close(); } else { cout << socket->getError() << "\n"; }</code>
<code></code>
Constructor Summary
Constructor
Destructor
Method Summary
<code> bool</code>
Closes the connection
Connects to the specified server and port
Connects to the specified server and port over a secure connection
<code> const char*</code>
Returns a description of the last known error
Inserts a CONNECT-Enabled HTTP proxy into the connect chain
Inserts a Socks4 server into the connect chain
Inserts a Socks5 server into the connect chain
Inserts a transparent tunnel into the connect chain
<code> int</code>
Reads a buffer of data from the connection
Reads a line from the connection
Reads everything available from the connection
Sends a buffer of data over the connection
Sends a null terminated string over the connection
<code> void</code>
Sets an output stream to receive realtime messages about the socket
Sets the timeout value for Connect, Read and Send operations.
<a></a>
Constructor Detail
<dl><dd>Constructor</dd></dl>
<dl><dd>Destructor</dd></dl>
Method Detail
<dl><dd>Closes the connection</dd></dl>
A connection must established before this method can be called
<dl><dd>Connects to the specified server and port</dd></dl>
If proxies have been specified, the connection passes through tem first.
<dl><dd>Connects to the specified server and port over a secure connection</dd></dl>
If proxies have been specified, the connection passes through them first.
<dl><dd>Returns a description of the last known error</dd></dl>
<dl><dd>Inserts a CONNECT-Enabled HTTP proxy into the connect chain</dd></dl>
Becomes the last server connected to in the chain before connecting to the destination server
<dl><dd>Inserts a Socks4 server into the connect chain</dd></dl>
<dl><dd>Inserts a Socks5 server into the connect chain</dd></dl>
<dl><dd>Inserts a transparent tunnel into the connect chain</dd></dl>
A transparent Tunnel is a server that accepts a connection on a certain port,
and always connects to a particular server:port address on the other side.
<dl><dd>Reads a buffer of data from the connection</dd></dl>
<dl><dd>Reads a line from the connection</dd></dl>
<dl><dd>Reads everything available from the connection</dd></dl>
<dl><dd>Sends a buffer of data over the connection</dd></dl>
<dl><dd>Sends a null terminated string over the connection</dd></dl>
The string can contain its own newline characters.
Returns false and sets the error message if it fails to send the line.
<dl><dd>Sets an output stream to receive realtime messages about the socket</dd></dl>
<dl><dd>Sets the timeout value for Connect, Read and Send operations.</dd></dl>
Setting the timeout to 0 removes the timeout - making the Socket blocking.
删除socket_platform.h檔案包含 #include <winsock2.h> 的代碼,以防止重寫義的問題