---
name: "socketbase"
section: "3bobcat"
platform: "linux"
package: "libbobcat-dev"
version: "6.07.01-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/socketbase"
---

# socketbase(3bobcat)

Base class for socket-constructing classes

## NAME

FBB::SocketBase - Base class for socket-constructing classes

## SYNOPSIS

**#include \<bobcat/socketbase\>**\
 Linking option: *-lbobcat*

## DESCRIPTION

This class is a base class for the **FBB::ServerSocket** and **FBB::ClientSocket** classes. Since it is designed as a base class, all its constructors are protected.

## NAMESPACE

**FBB**\
 All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace **FBB**.

## INHERITS FROM

**FBB::InetAddress**

## PROTECTED CONSTRUCTORS

- o

  **SocketBase(size\_t port)**:\
   This constructor creates a **SocketBase** to be used with **ServerSocket**-objects, listening on *port*.

-

  - o

  **SocketBase(std::string const &host, uint16\_t port)**:\
   This constructor creates a **FBB::SocketBase** to be used with a **ClientSocket**-object, connecting to *hostname*, at port \`*port*’.

These constructors throw a *std::exception* if they could not properly complete.

The copy constructor and copy assignment operator are available. Both offer protected access rights.

## PROTECTED MEMBER

- o

  **SocketBase makeBase(int socket, sockaddr\_in const &address)**:\
   This member returns  a **FBB::SocketBase** object initializing its socket and **FBB::InetAddress** from the provided arguments.

## MEMBER FUNCTIONS

All members of **FBB::InetAddress** are available, as **FBB::SocketBase** inherits from this class.

- o

  **bool debug() const**:\
   This accessor returns **true** if the socket’s *debug* (**SO\_DEBUG**) socket option is active. It throws an **FBB::Exception** exception if the status of the debug option could not be determined;

-

  - o

  **bool reuse() const**:\
   This accessor returns **true** if the socket’s *reuse* (**SO\_REUSEADDR**) socket option is active. It throws an **FBB::Exception** exception if the status of the reuse option could not be determined;

-

  - o

  **void setDebug(bool trueIsOn) const**:\
   This member may be used to modify the socket’s *debug* (**SO\_DEBUG**) socket option. It throws an **FBB::Exception** exception if the socket’s debug option could not be modified;

-

  - o

  **void setReuse(bool trueIsOn) const**:\
   This member may be used to modify the socket’s *reuse* (**SO\_REUSEADDR**) socket option. It throws an **FBB::Exception** exception if the socket’s reuse option could not be modified;

-

  - o

  **int socket() const**:\
   This accessor returns the **FBB::SocketBase**’s socket value.

## EXAMPLE

The classes *FBB::ClientSocket* and *FBB::ServerSocket* were derived from *SocketBase*. E.g.,

```
#ifndef INCLUDED_BOBCAT_CLIENTSOCKET_
#define INCLUDED_BOBCAT_CLIENTSOCKET_
#include <string>
#include <bobcat/socketbase>
#include <bobcat/exception>
namespace FBB
{
class ClientSocket: public SocketBase
{
    public:
                                // host may be address or name
        ClientSocket(std::string const &host, uint16_t port);
        int connect();          // returns fd (socket) to talk to the server
};
} // FBB
#endif
```

See the [**clientsocket**(3bobcat)](/clientsocket/3bobcat.md) man-page for an example showing how to use *FBB::ClientSocket*.

## FILES

*bobcat/socketbase* - defines the class interface

## SEE ALSO

[**bobcat**(7)](/bobcat/7.md), [**clientsocket**(3bobcat)](/clientsocket/3bobcat.md), [**inetaddress**(3bobcat)](/inetaddress/3bobcat.md), [**localsocketbase**(3bobcat)](/localsocketbase/3bobcat.md), [**serversocket**(3bobcat)](/serversocket/3bobcat.md)

## BUGS

None Reported.

## BOBCAT PROJECT FILES

- o

  *https://fbb-git.gitlab.io/bobcat/*: gitlab project page;

Debian Bobcat project files:

- o

  *libbobcat6*: debian package containing the shared library, changelog and copyright note;

- o

  *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**).
