StormByte C++ Library: Network module 0.0.9999
StormByte-Network is a StormByte library module for handling and create network connections
All Classes Namespaces Functions Variables Typedefs Pages
Public Member Functions | Protected Member Functions | List of all members
StormByte::Network::Server Class Referenceabstract

A server class. More...

#include <server.hxx>

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

Public Member Functions

 Server (Connection::Protocol protocol, std::shared_ptr< Connection::Handler > handler, std::shared_ptr< Logger > logger) noexcept
 Constructor.
 
 Server (const Server &other)=delete
 Copy constructor (deleted).
 
 Server (Server &&other) noexcept=default
 Move constructor.
 
virtual ~Server () noexcept override
 Destructor.
 
Serveroperator= (const Server &other)=delete
 Copy assignment operator (deleted).
 
Serveroperator= (Server &&other) noexcept=default
 Move assignment operator.
 
virtual ExpectedVoid Connect (const std::string &host, const unsigned short &port) noexcept override
 Starts the server.
 
virtual void Disconnect () noexcept override
 Stops a running server.
 
- Public Member Functions inherited from StormByte::Network::EndPoint
 EndPoint (const Connection::Protocol &protocol, std::shared_ptr< Connection::Handler > handler, std::shared_ptr< Logger > logger) noexcept
 Constructs an EndPoint with the specified protocol, handler, and logger.
 
 EndPoint (const EndPoint &other)=delete
 Deleted copy constructor to prevent copying.
 
 EndPoint (EndPoint &&other) noexcept=default
 Defaulted move constructor.
 
virtual ~EndPoint () noexcept
 Virtual destructor for proper cleanup in derived classes.
 
EndPointoperator= (const EndPoint &other)=delete
 Deleted copy assignment operator to prevent copying.
 
EndPointoperator= (EndPoint &&other) noexcept=default
 Defaulted move assignment operator.
 
const Connection::Protocol & Protocol () const noexcept
 Retrieves the protocol used by the endpoint.
 
Connection::Status Status () const noexcept
 Retrieves the current connection status of the endpoint.
 

Protected Member Functions

Socket::Client & AddClient (Socket::Client &&client) noexcept
 The function to add a client to client's vector for store and ownership handling.
 
void RemoveClient (Socket::Client &client) noexcept
 The function to remove a client from client's vector.
 
void RemoveClientAsync (Socket::Client &client) noexcept
 The function to remove a client from client's vector in async way.
 
void DisconnectClient (Socket::Client &client) noexcept
 The function to disconnect a client (but not remove from vector).
 
virtual Expected< void, PacketErrorProcessClientPacket (Socket::Client &client, const Packet &packet) noexcept=0
 The function to process a client packet and returns a reply.
 
- Protected Member Functions inherited from StormByte::Network::EndPoint
virtual ExpectedVoid Handshake (Socket::Client &client) noexcept
 Sets up the connection handler for the endpoint.
 
virtual ExpectedVoid Authenticate (Socket::Client &client) noexcept
 Authenticates the client connection.
 
ExpectedPacket Receive (Socket::Client &client) noexcept
 Receives packet from the client processing pipeline before constructing packet.
 
ExpectedPacket RawReceive (Socket::Client &client) noexcept
 Receives packet from the client without processing pipeline before constructing packet.
 
ExpectedVoid Send (Socket::Client &client, const Packet &packet) noexcept
 Sends a packet to the client processing pipeline before sending packet.
 
ExpectedVoid RawSend (Socket::Client &client, const Packet &packet) noexcept
 Sends a packet to the client without processing pipeline before sending packet.
 

Additional Inherited Members

- Protected Attributes inherited from StormByte::Network::EndPoint
Connection::Protocol m_protocol
 The protocol used by the endpoint (e.g., IPv4, IPv6).
 
std::shared_ptr< Connection::Handlerm_handler
 Shared pointer to the connection handler.
 
std::shared_ptr< Logger > m_logger
 Shared pointer to the logger instance.
 
std::atomic< Connection::Status > m_status
 The current connection status of the endpoint.
 
Socket::Socket * m_socket
 Unique pointer to the socket instance.
 
Buffer::Pipeline m_input_pipeline
 
Buffer::Pipeline m_output_pipeline
 The input/output pipeline for processing data.
 

Detailed Description

A server class.

Constructor & Destructor Documentation

◆ Server() [1/3]

StormByte::Network::Server::Server ( Connection::Protocol  protocol,
std::shared_ptr< Connection::Handler handler,
std::shared_ptr< Logger >  logger 
)
noexcept

Constructor.

Parameters
protocolThe protocol to use.
handlerThe handler to use.

◆ Server() [2/3]

StormByte::Network::Server::Server ( const Server other)
delete

Copy constructor (deleted).

Parameters
otherThe other instance.

◆ Server() [3/3]

StormByte::Network::Server::Server ( Server &&  other)
defaultnoexcept

Move constructor.

Parameters
otherThe other instance.

Member Function Documentation

◆ AddClient()

Socket::Client & StormByte::Network::Server::AddClient ( Socket::Client &&  client)
protectednoexcept

The function to add a client to client's vector for store and ownership handling.

Parameters
clientThe client to add.
Returns
The reference to the added client.

◆ Connect()

virtual ExpectedVoid StormByte::Network::Server::Connect ( const std::string &  host,
const unsigned short &  port 
)
overridevirtualnoexcept

Starts the server.

Parameters
hostThe host to use.
portThe port to use.
Returns
True if the server started successfully, false otherwise.

Implements StormByte::Network::EndPoint.

◆ Disconnect()

virtual void StormByte::Network::Server::Disconnect ( )
overridevirtualnoexcept

Stops a running server.

Reimplemented from StormByte::Network::EndPoint.

◆ DisconnectClient()

void StormByte::Network::Server::DisconnectClient ( Socket::Client &  client)
protectednoexcept

The function to disconnect a client (but not remove from vector).

Parameters
clientThe client to disconnect.

◆ operator=() [1/2]

Server & StormByte::Network::Server::operator= ( const Server other)
delete

Copy assignment operator (deleted).

Parameters
otherThe other instance.
Returns
The new instance.

◆ operator=() [2/2]

Server & StormByte::Network::Server::operator= ( Server &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherThe other instance.
Returns
The new instance.

◆ ProcessClientPacket()

virtual Expected< void, PacketError > StormByte::Network::Server::ProcessClientPacket ( Socket::Client &  client,
const Packet packet 
)
protectedpure virtualnoexcept

The function to process a client packet and returns a reply.

This function is called when a client sends a packet to the server so the derived class can process the packet and optionally send a reply. If the function returns an unexpected it will be logged and the client will be disconnected.

Parameters
clientThe client to process the message for.
messageThe message to process.
Returns
The expected result of the operation.

◆ RemoveClient()

void StormByte::Network::Server::RemoveClient ( Socket::Client &  client)
protectednoexcept

The function to remove a client from client's vector.

Parameters
clientThe client to remove.

◆ RemoveClientAsync()

void StormByte::Network::Server::RemoveClientAsync ( Socket::Client &  client)
protectednoexcept

The function to remove a client from client's vector in async way.

Parameters
clientThe client to remove.

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