天天看點

c++ socket 用戶端庫 socks5 用戶端 RudeSocket™ Open Source C++ Socket Library介紹用法編譯:

一個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-&gt;connect("google.com", 80); socket-&gt;sends("GET / HTTP/1.0\n\n"); const char *response = socket-&gt;reads(); cout &lt;&lt; response; socket-&gt;close();</code>

SSL Usage

<code>Socket *socket = new Socket(); socket-&gt;connectSSL("google.com", 443); socket-&gt;sends("GET / HTTP/1.0\n\n"); const char *response = socket-&gt;reads(); cout &lt;&lt; response; socket-&gt;close();</code>

Chaining Connections

<code>Socket *socket = new Socket(); socket-&gt;insertSocks4("12.34.56.78", 8000, "username"); socket-&gt;insertSocks5("12.34.56.78", 8000, "username", "password"); socket-&gt;insertProxy("12.34.56.78", 8080); socket-&gt;connectSSL("google.com", 443); socket-&gt;sends("GET / HTTP/1.0\n\n"); const char *response = socket-&gt;reads(); cout &lt;&lt; response; socket-&gt;close();</code>

Adding Error checking

<code>Socket *socket = new Socket(); if(socket-&gt;connectSSL("google.com", 443)) {   if(socket-&gt;sends("GET / HTTP/1.0\n\n"))   {     const char *response = socket-&gt;reads();     if(response)     {       cout &lt;&lt; response;     }     else     {       cout &lt;&lt; socket-&gt;getError() &lt;&lt; "\n";     }   }   else   {     cout &lt;&lt; socket-&gt;getError() &lt;&lt; "\n";   }   socket-&gt;close(); } else {   cout &lt;&lt; socket-&gt;getError() &lt;&lt; "\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 &lt;winsock2.h&gt; 的代碼,以防止重寫義的問題