FBB::ClientSocket(3bobcat)

πŸ’– FBB::ClientSocket(3bobcat) πŸ’–

okay bestie, sit down, hydrate, because we're talking about FBB::ClientSocket β€” the third bobcat manual page (yes, 3bobcat, that's the vibe) for the class that lets you slide into some server's DMs over the Internet. ✨


🌸 NAME 🌸

FBB::ClientSocket β€” a Client Socket that connects to a Server in the Internet. it's giving main character connecting to the group chat, fr fr. πŸ¦‹


✨ SYNOPSIS ✨

#include <bobcat/clientsocket>
Linking option: -lbobcat

like yes, include the header, link the lib, we move. πŸ’…


πŸ‘‘ DESCRIPTION πŸ‘‘

so basically: you can construct an FBB::ClientSocket and have it connect to some server process out there in the internet. the socket it hands you can be used to initialize a std::istream and/or a std::ostream. the std::istream is for reading info from the server process that your FBB::ClientSocket connects to, and the std::ostream is for sending info to that same server process. 🫢

and since a socket is lowkey just a file descriptor, you can profitably use the FBB::IFdStream, FBB::IFdStreamBuf, FBB::OFdStream, and FBB::OFdStreamBuf classes here. obsessed. 😌

⚠️ but bestie, heads up: having a socket available does not mean the communication protocol is defined. nope! it's (still) the programmer's responsibility to comply with an existing protocol, or to implement a tailor-made protocol. and that second situation means the sequence of input- and output operations is defined by you, the programmer. no cap. 😭

oh and also β€” a Unix Domain client socket can be defined using FBB::LocalClientSocket. different class, different lore. 🧚


🌈 NAMESPACE 🌈

FBB

all constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. periodt. πŸ’œ


⭐ INHERITS FROM ⭐

FBB::SocketBase

it's giving family tree, and we're the well-behaved child. πŸŽ€


πŸŽ€ CONSTRUCTOR πŸŽ€

  • ClientSocket(std::string const &host, uint16_t port) β€” this constructor initializes an FBB::ClientSocket object, getting it all ready for a connection to the specified port at the given host. if the socket could not be constructed, an FBB::Exception gets thrown. 😀 and here's the thing β€” constructing the socket does not mean a connection has actually been established. to actually connect to the server, you gotta use the member connect() (peep below). ✨

Copy and move constructors (and assignment operators) are not available. πŸ™ˆ like, they're just not. don't ask, it's not happening.


πŸ’… MEMBER FUNCTIONS πŸ’…

all members of FBB::SocketBase (and therefore of FBB::InetAddress) are available, because FBB::ClientSocket inherits from these classes. inherited the whole wardrobe, basically. πŸ‘‘

  • int connect() β€” this member returns a socket that can be used to communicate with the server process. an FBB::Exception exception is thrown if the connection could not be established, or if the SocketBase base class could not properly be constructed. so yeah, wrap it, bestie. πŸ”₯

πŸ¦‹ EXAMPLE πŸ¦‹

see also the serversocket(3bobcat) example. πŸ‘€

#include <iostream>
#include <string>
#include <bobcat/clientsocket>
#include <bobcat/ifdstream>
#include <bobcat/ofdstream>

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
try
{
    if (argc == 1)
    {
        cerr << "Provide servername and port number\n";
        return 1;
    }

    size_t     port = stoul(argv[2]);
    ClientSocket client(argv[1], port);
    int fd = client.connect();
    string line;

    cout << "Connecting to socket " << fd << endl <<
            "address = " << client.dottedDecimalAddress() << ", " <<
                                                                 endl <<
            "communication through port " << client.port() << endl;

    IFdStream in(fd);                 // stream to read from
    OFdStream out(fd);                // stream to write to

    while (true)
    {
                                // Ask for a textline, stop if
        cout << "? ";           // empty / none
        if (!getline(cin, line) || line.length() == 0)
            return 0;
        cout << "Line read: " << line << endl;

                                // Return the line to the server
        out << line.c_str() << endl;
        cout << "wrote line\n";

        getline(in, line);      // Wait for a reply from the server
        cout << "Answer: " << line << endl;
    }
}
catch (Exception const &err)
{
    cerr << err.what() << "\n" <<
            "Can’t connect to " << argv[1] << ", port " <<
            argv[2] << endl;
    return 1;
}

πŸ“ FILES πŸ“

bobcat/clientsocket β€” defines the class interface. that's it, that's the file, she's the blueprint. πŸ“„βœ¨


πŸ’œ SEE ALSO πŸ’œ

bobcat(7), ifdstream(3bobcat), ifdbuf(3bobcat), inetaddress(3bobcat), localclientsocket(3bobcat), ofdstream(3bobcat), ofdstream(3bobcat), serversocket(3bobcat), socketbase(3bobcat)

(yes ofdstream(3bobcat) is listed twice β€” iconic of it, honestly, we respect the double feature πŸ’€)


πŸ’€ BUGS πŸ’€

None Reported.

literally flawless. not a single bug to drag. we love to see it. 😌✨


🌟 BOBCAT PROJECT FILES 🌟

Debian Bobcat project files:

  • libbobcat6: debian package containing the shared library, changelog and copyright note;
  • libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;

🧚 BOBCAT 🧚

Bobcat is an acronym of Brokken’s Own Base Classes And Templates. yes bestie, it's a backronym and it ATE. πŸ”₯


This is free software, distributed under the terms of the GNU General Public License (GPL).

free as in freedom, slay as in slay. 🫢


πŸ’– AUTHOR πŸ’–

Frank B. Brokken (f.b.brokken@rug.nl).

the legend herself/himself, the icon, the moment. πŸ‘‘


and that's the whole page diva!! πŸŽ€ source and version: libbobcat-dev_6.15.01, dated 2005-2026, and yes this manual page is literally called FBB::ClientSocket(3bobcat) β€” go connect to something, bestie, but remember: implement your protocol first. no cap. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from