FBB::Lo...rSocket(3bobcat)
π NAME π
FBB::LocalServerSocket β bestie, it's the Unix Domain Server socket that accepts connection requests β¨ (and yes, this page is straight out of the bobcat manual, section 3bobcat, so you know it's real π«Ά)
π SYNOPSIS π
#include <bobcat/localserversocket>
Linking option: -lbobcat
πΈ DESCRIPTION πΈ
An FBB::LocalServerSocket is a Unix Domain server socket, and its whole job is listening for connection requests coming from the local host over a Unix Domain socket. No network, no drama, just localhost vibes π
Connection requests can get accepted in either blocking or non-blocking mode β you pick. When a connection finally gets accepted, out pops a socket, and that socket is what you use to read info from the client or write info back to it.
Now here's the cute part: the socket you get is a file descriptor, which means you can absolutely use it to initialize a std::istream and/or a std::ostream π
- the
std::istreamis for reading info from the client process - the
std::ostreamis for sending info to the client process
And because a socket is basically just a file descriptor, the existing FBB::IFdStream, FBB::IFdStreamBuf, FBB::OFdStream, and FBB::OFdStreamBuf classes are so usable here β they were literally made for this, iykyk.
β οΈ But bestie, listen β having a socket does not mean you have a communication protocol. That's still 100% on the programmer: either comply with an existing protocol, or implement a tailor-made one. And in that second case, the sequence of input and output operations is defined by you, the programmer. No cap.
π¦ NAMESPACE π¦
FBB
All constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB.
π INHERITS FROM π
FBB::LocalSocketBase
π ENUMERATION π
The following enumeration is defined in the class FBB::LocalServerSocket:
enum Socket β this enumeration holds two values:
KEEPβ when this value is specified at construction time, the file representing the Unix Domain Socket is not removed when theLocalServerSocketis destroyed.UNLINKβ when this value is specified at construction time, the file representing the Unix Domain Socket is removed when theLocalServerSocketis destroyed. And since a socket cannot be reused, this is the default value used with theLocalServerSocketconstructor. periodt.
π CONSTRUCTOR π
LocalServerSocket()β this constructor creates an empty (non-functioning)FBB::LocalServerSocketobject. Before you can do literally anything with it, you have to call theopen()member (peep below π).LocalServerSocket(string const &name, Socket action = UNLINK) throw (Exception)β this constructor initializes anFBB::LocalServerSocketobject, and it will listen for connection requests using the named Unix Domain socket. AnFBB::Exceptionis thrown if the socket could not be constructed. If the constructor is given a second argumentFBB::LocalServerSocket::KEEP, the constructed socket is not unlinked when theFBB::LocalServerSocketobject is destroyed. And ngl, constructing the socket does not mean the object is actually listening for connections yet β to start listening, the memberlisten()should be called.- Copy and move constructors (and assignment operators) are not available. Not invited to the party, sorry. π
β¨ MEMBER FUNCTIONS β¨
size_t accept()β theaccept()member returns ansize_twhich is a file descriptor (socket) that may be used to communicate with the client requesting the connection. In more complex programs, that returned file descriptor (socket) could be passed to a class derived fromFBB::Fork, handling the communication with the child as a separate (child) process. main character energy fr fr.void listen(size_t backlog = 5, bool blocking = true)β thelisten()member defines the way theFBB::LocalServerSocketwill listen for clients requesting a connection. Heads up: it can be used only once with aFBB::LocalServerSocket. AnFBB::Exceptionobject is thrown if listening fails.- The
listen()member'sbacklogparameter defines the size of theFBB::LocalServerSocket's internal queue, where connection requests may be stored waiting for their turn to be serviced. Whenbacklogrequests are waiting and another request arrives, then that request is lost. π - The member's second parameter,
blocking, is used to control the blocking mode. By default, blocking is used, andlisten()will wait until a connection is established. This is ok in situations where clients connect infrequently and for relatively short time intervals. Otherwise, in more complex programs, anFBB::Selectorobject can be used to sense input on the server socket and/or on various client sockets.
- The
void open(string const &name, Socket action = UNLINK)β this member prepares aFBB::LocalServerSocketobject for use. It should only be used in combination with the default constructor. Followingopen()theFBB:::LocalServerSocketobject will be able to listen for connection requests using the named Unix Domain socket. AnFBB::Exceptionis thrown if the socket could not be constructed. If the a second argumentFBB::LocalServerSocket::KEEP, is provided the constructed socket is not unlinked when theFBB::LocalServerSocketobject is destroyed. The construction of the socket does not mean that theFBB::LocalServerSocketobject is actually listening for connections. To start listening, the memberlisten()should be called next.
π EXAMPLE π
See also the localclientsocket(3bobcat) example. π
#include <iostream>
#include <bobcat/localserversocket>
#include <bobcat/ifdstream>
#include <bobcat/ofdstream>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
try
{
if (argc == 1)
{
cerr << "Provide local filename, e.g., /tmp/uds\n";
return 1;
}
LocalServerSocket server(argv[1]);
cerr << "server using `" << argv[1] << "β" << endl;
cout <<
"The server terminates when it receives a single `qβ on a line\n"
"A connection is terminated when no input is received anymore.\n"
"Then another connection is possible" << endl;
server.listen(); // listen in blocking mode
while (true)
{
int fd = server.accept();
cerr << "Client FD = " << fd << ", " << endl;
IFdStream in(fd); // stream to read from client
OFdStream out(fd); // stream to write to client
string cmd;
while (getline(in, cmd))
{
cout << "Got: " << cmd << endl;
out << "Got: " << cmd << "\r" << endl;
if (cmd[0] == βqβ)
return 0;
}
cout << "Ready for another connection\n";
}
}
catch (Exception const &err)
{
cerr <<
err.what() << endl <<
"Server socket on port " << argv[1] <<
" canβt be opened" << endl;
return -1;
}
π§ FILES π§
bobcat/serversocket- defines the class interface
π₯ SEE ALSO π₯
bobcat(7), localclientsocket(3bobcat), fork(3bobcat), ifdstream(3bobcat), ifdbuf(3bobcat), localsocketbase(3bobcat), ofdstream(3bobcat), ofdstream(3bobcat), select(2), selector(3bobcat), serversocket(3bobcat)
π BUGS π
None Reported. (clean sheet, we love to see it β¨)
π BOBCAT PROJECT FILES π
- https://fbb-git.gitlab.io/bobcat/: gitlab project page;
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β.
π COPYRIGHT π
This is free software, distributed under the terms of the GNU General Public License (GPL).
πΈ AUTHOR πΈ
Frank B. Brokken (f.b.brokken@rug.nl).
okay bestie that's the whole page, you're fully caught up π this was the FBB::Lo...rSocket(3bobcat) page, served fresh from libbobcat-dev_6.15.01, dated 2005-2026 β slay, go build something cute with it πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms