rudesocket - Man Page

Library (C++ API) for making Client Socket Connections

Synopsis

	#include <rude/socket.h>
	
    rude::Socket *socket = new Socket();
    socket->connect('example.com', 80);
    socket->sends('GET / HTTP/1.00n');
    const char *response = socket->reads();
    cout << response;
    socket->close();

Public Member Functions

Socket ()
Constructor.
~Socket ()
Destructor.
void setTimeout (int seconds, int microseconds)
Sets the timeout value for Connect, Read and Send operations.
const char * getError ()
Returns a description of the last known error.
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.
bool insertTunnel (const char *server, int port)
Inserts a transparent tunnel 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 insertSocks4 (const char *server, int port, const char *username)
Inserts a Socks4 server into the connect chain.
bool insertProxy (const char *server, int port)
Inserts a CONNECT-Enabled HTTP proxy into the connect chain.
int send (const char *data, int length)
Sends a buffer of data over the connection.
int read (char *buffer, int length)
Reads a buffer of data from the connection.
const char * reads ()
Reads everything available from the connection.
const char * readline ()
Reads a line from the connection.
bool sends (const char *buffer)
Sends a null terminated string over the connection.
bool close ()
Closes the connection.
void setMessageStream (std::ostream &o)
Sets an output stream to receive real-time messages about the socket.

Detailed Description

The public interface to the Socket component.

If you are using windows, you will need to initiate the winsock DLL yourself, and finish the DLL yourself when you are done using the component.

General Usage

    Socket *socket = new Socket();
    socket->connect('example.com', 80);
    socket->sends('GET / HTTP/1.00n');
    const char *response = socket->reads();
    cout << response;
    socket->close();

SSL Usage

    Socket *socket = new Socket();
    socket->connectSSL('example.com', 443);
    socket->sends('GET / HTTP/1.00n');
    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('example.com', 443);
    socket->sends('GET / HTTP/1.00n');
    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.00n'))
        {
            const char *response = socket->reads();
            if(response)
            {
                cout << response;
            }
            else
            {
                cout << socket->getError() << '0;
            }
        }
        else
        {
            cout << socket->getError() << '0;
        }
        socket->close();
    }
    else
    {
        cout << socket->getError() << '0;
    }

Constructor & Destructor Documentation

rude::Socket::Socket ()

Constructor.

rude::Socket::~Socket ()

Destructor.

Member Function Documentation

bool rude::Socket::close ()

Closes the connection.

A connection must established before this method can be called

bool rude::Socket::connect (const char * server, int port)

Connects to the specified server and port.

If proxies have been specified, the connection passes through tem first.

bool rude::Socket::connectSSL (const char * server, int port)

Connects to the specified server and port over a secure connection.

If proxies have been specified, the connection passes through them first.

const char* rude::Socket::getError ()

Returns a description of the last known error.

bool rude::Socket::insertProxy (const char * server, int port)

Inserts a CONNECT-Enabled HTTP proxy into the connect chain.

Becomes the last server connected to in the chain before connecting to the destination server

bool rude::Socket::insertSocks4 (const char * server, int port, const char * username)

Inserts a Socks4 server into the connect chain.

Becomes the last server connected to in the chain before connecting to the destination server

bool rude::Socket::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 to in the chain before connecting to the destination server

bool rude::Socket::insertTunnel (const char * server, int port)

Inserts a transparent tunnel into the connect chain.

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. Becomes the last server connected to in the chain before connecting to the destination server

int rude::Socket::read (char * buffer, int length)

Reads a buffer of data from the connection.

A connection must established before this method can be called

const char* rude::Socket::readline ()

Reads a line from the connection.

A connection must established before this method can be called

const char* rude::Socket::reads ()

Reads everything available from the connection.

A connection must established before this method can be called

int rude::Socket::send (const char * data, int length)

Sends a buffer of data over the connection.

A connection must established before this method can be called

bool rude::Socket::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

void rude::Socket::setMessageStream (std::ostream & o)

Sets an output stream to receive real-time messages about the socket.

void rude::Socket::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.

See Also

rudecgiparser(3), rudeconfig(3), rudedatabase(3), rudesession(3)

Reporting Problems

Before reporting a problem, please check the rudeserver.com web site to verify that you have the latest version of rudesocket; otherwise, obtain the latest version and see if the problem still exists.  Please read the  FAQ at:

             http://www.rudeserver.com/

before asking for help.  Send questions and/or comments to  matt@rudeserver.com

Authors

Copyright (C) 2000-2008 Matthew Flood (matt@rudeserver.com)

This  software is provided "as-is," without any express or implied warranty.  In no event will the authors be held liable for any damages arising from the use of this software.  See the distribution directory with respect  to  requirements  governing  redistribution. Thanks to all the people who reported problems and suggested various improvements in rudesocket; who are too numerous to cite here.

Referenced By

rudeconfig(3).

15 Jan 2008 Version 1.1.0 User Manuals