StormByte C++ Library: Network module 0.0.9999
StormByte-Network is a StormByte library module for handling and create network connections
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
StormByte::Network::Client Class Reference

Abstract base class for application-specific clients. More...

#include <client.hxx>

Inheritance diagram for StormByte::Network::Client:
Inheritance graph
[legend]
Collaboration diagram for StormByte::Network::Client:
Collaboration graph
[legend]

Public Member Functions

 Client (const DeserializePacketFunction &deserialize_packet_function, std::shared_ptr< Logger::Log > logger) noexcept
 Constructs a Client instance.
 
 Client (const Client &other)=delete
 Copy constructor (deleted).
 
 Client (Client &&other) noexcept=default
 Move constructor.
 
virtual ~Client () noexcept
 Virtual destructor (abstract).
 
Clientoperator= (const Client &other)=delete
 Copy-assignment operator (deleted).
 
Clientoperator= (Client &&other) noexcept=default
 Move-assignment operator.
 
bool Connect (const Connection::Protocol &protocol, const std::string &address, const unsigned short &port) override
 Establish a connection to a server.
 
void Disconnect () noexcept override
 Disconnect from the server, if connected.
 
Connection::Status Status () const noexcept override
 Query the current connection status.
 

Protected Member Functions

PacketPointer Send (const Transport::Packet &packet) noexcept
 Send a Transport::Packet to the connected server and receive a reply.
 

Detailed Description

Abstract base class for application-specific clients.

Derive from Client to implement your application's client-side logic. The modern API expects a deserializer function (see DeserializePacketFunction) and a Logger::ThreadedLog instance to be provided to the Client constructor. Subclasses typically implement lightweight, domain-specific helper methods that call the protected Send() helper to perform synchronous request/response flows.

Key extension points:

The protected Send() helper sends a Transport::Packet to the server and returns a PacketPointer referencing the reply (or nullptr on failure). Use Connect() / Disconnect() to manage the connection.

Constructor & Destructor Documentation

◆ Client()

StormByte::Network::Client::Client ( const DeserializePacketFunction deserialize_packet_function,
std::shared_ptr< Logger::Log >  logger 
)
inlinenoexcept

Constructs a Client instance.

Parameters
deserialize_packet_functionFunction used to deserialize incoming transport packets into domain Packet objects.
loggerLogger instance used for diagnostic messages.

◆ ~Client()

virtual StormByte::Network::Client::~Client ( )
virtualnoexcept

Virtual destructor (abstract).

Kept pure to make Client abstract; derived classes must provide an implementation (even if defaulted) in a translation unit.

Member Function Documentation

◆ Connect()

bool StormByte::Network::Client::Connect ( const Connection::Protocol &  protocol,
const std::string &  address,
const unsigned short &  port 
)
overridevirtual

Establish a connection to a server.

Parameters
protocolProtocol parameters to use for the connection.
addressServer address (hostname or IP string).
portServer port number.
Returns
true if the connection was established, false otherwise.

Implements StormByte::Network::Endpoint.

◆ Disconnect()

void StormByte::Network::Client::Disconnect ( )
overridevirtualnoexcept

Disconnect from the server, if connected.

Implements StormByte::Network::Endpoint.

◆ Send()

PacketPointer StormByte::Network::Client::Send ( const Transport::Packet packet)
protectednoexcept

Send a Transport::Packet to the connected server and receive a reply.

Subclasses should use this protected helper to perform request/response interactions with the server. The function returns a PacketPointer referencing the response packet, or nullptr if the send or receive operation failed.

Parameters
packetThe transport-level packet to send.
Returns
PacketPointer to the response packet, or nullptr on error.

◆ Status()

Connection::Status StormByte::Network::Client::Status ( ) const
overridevirtualnoexcept

Query the current connection status.

Returns
Current Connection::Status representing the connection state.

Implements StormByte::Network::Endpoint.


The documentation for this class was generated from the following file: