Introduced
A C + + socket client Library
Http://www.rudeserver.com/socket/index.html
The rudesocket™open Source C + + Socket Library provides a simple to use interface for creating and using client S Ockets. You can connect to the destination server through an unlimited number of chainable proxies, SOCKS4 and SOCKS5 servers if a Nonymity or security is a priority. Supports SSL [1] as well as normal connections. Supports timeouts. Full version requires that OpenSSL libraries is installed. However, a lite version is available if SSL is not required or available.
The library is currently available for Linux development environments.
Features:
- SSL Support (Linux and Windows) [1]
- Supports Sockes 4, Socks 5, HTTP Proxy
- Like any rudeserver libraries:simple and easy to use.
- Open Source and free
- Platform Independent Interface
[1]-this product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)
Usage
General Usage
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();
SSL Usage
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();
Chaining Connections
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();
Adding Error Checking
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";
}
Constructor Summary |
Socket() Constructor |
~Socket() destructor |
Method Summary |
bool |
close() Closes the connection |
bool |
connect( const char* server, int port ) Connects to the specified server and port |
bool |
connectSSL( const char* server, int port ) Connects to the specified server and port over a secure connection |
const char* |
getError() Returns a description of the last known error |
bool |
insertProxy( const char* server, int port ) Inserts a connect-enabled HTTP proxy into the CONNECT chain |
bool |
insertSocks4( const char* server, int port, const char* username ) Inserts a SOCKS4 server into the Connect chain |
bool |
insertSocks5( const char* server, int port, const char* username, const char* password ) Inserts a SOCKS5 server into the Connect chain |
bool |
insertTunnel( const char* server, int port ) Inserts a transparent tunnel into the Connect chain |
int |
read( char* buffer, int length ) Reads a buffer of data from the connection |
const char* |
readline() Reads a line from the connection |
const char* |
reads() Reads everything available from the connection |
int |
send( const char* data, int length ) Sends a buffer of data over the connection |
bool |
sends( const char* buffer ) Sends a null terminated string over the connection |
void |
setMessageStream( std::ostream& o ) Sets an output stream to receive realtime messages about the socket |
void |
setTimeout( int seconds, int microseconds ) Sets the timeout value for Connect, Read and Send operations. |
Socket
Socket ();
-
Constructor
~socket
~socket ();
-
destructor
Close
Close ();
-
Closes the connection
A connection must established before this method can be called
Connect
Connect (const char* Server, int port);
Connects to the
-
specified server and port
IF proxies has been specified, the connection passes through TEM first.
Connectssl
Connectssl (const char* Server, int port);
-
Connects to the specified server and port over a secure connection
IF proxies has been specified, the connection passes through them first.
GetError
GetError ();
-
Returns A description
of the Last known error
Insertproxy
Insertproxy (const char* Server, int port);
-
Inserts a connect-enabled HTTP proxy into the CONNECT chain
becomes the last server connected into the chain before connecting to the destination server
InsertSocks4
INSERTSOCKS4 (const char* Server, int port, const char* username);
-
Inserts a SOCKS4 server into the Connect chain
becomes the last server connected into the chain before connecting to the destination server
InsertSocks5
INSERTSOCKS5 (const char* Server, int port, const char* username, const char* password);
-
Inserts a SOCKS5 server into the Connect chain
becomes the last server connected into the chain before connecting to the destination server
Inserttunnel
Inserttunnel (const char* Server, int port);
-
Inserts a transparent tunnel into the Connect chain
A transparent tunnel is a server which accepts a connection on a certain port,
And always connects to a particular Server:port address in the other side.
becomes the last server connected into the chain before connecting to the destination server
Read
Read (char* buffer, int length);
-
Reads A buffer of data from the connection
A connection must established before this method can be called
ReadLine
ReadLine ();
Reads a line from the
-
connection
A connection must established before this method can be called
Reads
reads ();
-
Reads Everything available from the connection
A connection must established before this method can be called
Send
Send (const char* data, int length);
-
sends a buffer of data over the connection
A connection must established before this method can be called
Sends
sends (const char* buffer);
-
sends a null terminated string over the connection
The string can contain its own newline characters.
Returns false and sets the error message if it fails to send the line.
A connection must established before this method can be called
Setmessagestream
Setmessagestream (std::ostream& O);
-
sets an output stream to receive realtime messages
about the socket
SetTimeout
SetTimeout (int seconds, int microseconds);
-
Sets the timeout value for Connect, Read and Send operations.
Setting The timeout to 0 removes the timeout-making the Socket blocking.
Compile:
Official Original source download: Click to download
Remove the socket_platform.h file that contains the code #include <winsock2.h> to prevent overriding the problem
C + + Socket client library SOCKS5 client Rudesocket? Open Source C + + Socket Library