rudesocket(3)

πŸ“¦ version 1.3.0, in fedora 43, fedora 44

🌸 rudesocket β€” the C++ socket bestie you've been looking for πŸ’…

okay so bestie, we're in rudesocket(3) territory, part of the User Manuals collection. this is the C++ API for making client socket connections and honestly? she's giving main character energy. let's get into it ✨


✨ NAME ✨

rudesocket β€” a 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.00);
    const char *response = socket->reads();
    cout << response;
    socket->close();

πŸ’– Public Member Functions πŸ’–

  • Socket () β€” Constructor. baby's first socket πŸŽ€
  • ~Socket () β€” Destructor. say bye bestie πŸ‘‹
  • void setTimeout (int seconds, int microseconds) β€” sets how long Connect, Read and Send operations are allowed to hang around waiting πŸ’…
  • const char * getError () β€” hands you a description of the last known error, so you know exactly what went wrong 😭
  • bool connect (const char *server, int port) β€” connects to the server and port you specify 🫢
  • bool connectSSL (const char *server, int port) β€” same deal but the connection is secure πŸ”’βœ¨
  • bool connectSSL (const char *server, int port) β€” (yes, over a secure connection, we said what we said πŸ’œ)
  • bool insertTunnel (const char *server, int port) β€” slips a transparent tunnel into the connect chain 🌈
  • bool insertSocks5 (const char *server, int port, const char *username, const char *password) β€” slips a Socks5 server into the connect chain 🧦
  • bool insertSocks4 (const char *server, int port, const char *username) β€” slips a Socks4 server into the connect chain 🧦
  • bool insertProxy (const char *server, int port) β€” slips a CONNECT-Enabled HTTP proxy into the connect chain πŸ›°οΈ
  • int send (const char *data, int length) β€” sends a whole buffer of data over the connection πŸ“€
  • int read (char *buffer, int length) β€” reads a buffer of data off the connection πŸ“₯
  • const char * reads () β€” reads everything that's available from the connection, greedy queen πŸ‘‘
  • const char * readline () β€” reads just one line from the connection ✏️
  • bool sends (const char *buffer) β€” sends a null terminated string over the connection πŸ’Œ
  • bool close () β€” closes the connection, we're done here πŸšͺ
  • void setMessageStream (std::ostream &o) β€” sets an output stream to receive real-time messages about the socket, like a little live commentary feed πŸ“‘
lowkey important note: that list above is the exact roster from the original, and no, I did not merge the two connectSSL lines β€” they were both there, so they're both here. no cap. πŸ’€

✨ Detailed Description ✨

The public interface to the Socket component. that's her. that's the whole vibe 🫢

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. like, nobody's gonna do it for you bestie, you gotta do your own winsock homework 🌸

✨ General Usage ✨

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

πŸ”— Chaining Connections πŸ”—

okay this is the part where it gets ✨iconic✨ β€” you stack up your hops and she walks the whole chain:

    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.00);
    const char *response = socket->reads();
    cout << response;
    socket->close();

🚨 Adding Error checking 🚨

the glow-up where you stop living dangerously and start checking your return values:

    Socket *socket = new Socket();
    if(socket->connectSSL('google.com', 443))
    {
        if(socket->sends('GET / HTTP/1.00))
        {
            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. she is born πŸ’–

πŸŽ€ rude::Socket::~Socket ()

Destructor. she is gone 😭


✨ Member Function Documentation ✨

πŸ’… bool rude::Socket::close ()

Closes the connection.

A connection must established before this method can be called. like, you can't close something that was never open, bestie πŸ™ˆ

πŸ’… 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. (typo's theirs, love that for them 🫢)

πŸ’… 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. receipts, basically 🧾

πŸ’… 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. she queues up right at the front of the line πŸ‘‘

πŸ’… 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. so it's a no-thoughts-just-forwarding situation πŸŒ€

πŸ’… 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.

bestie note: yes, if it fails it returns false and sets the error message β€” so go read getError() after. it's giving "I told you so" πŸ’€

πŸ’… void rude::Socket::setMessageStream (std::ostream & o)

Sets an output stream to receive real-time messages about the socket. live tweeting, but for sockets πŸ“‘βœ¨

πŸ’… 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. so zero means "wait forever", not "give up instantly" β€” read that twice πŸ”₯


✨ SEE ALSO ✨

rudecgiparser(3), rudeconfig(3), rudedatabase(3), rudesession(3) β€” the whole rude family, go say hi πŸ«ΆπŸ’œ


✨ 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. πŸŒˆπŸ‘‘


and that's the whole page bestie!! this was Version 1.1.0, dated 15 Jan 2008 β€” yeah she's an elder but she still ate πŸ’…βœ¨ go make some sockets, ily, bye πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from