P2P File Share
A simple peer-to-peer file sharing system.
Loading...
Searching...
No Matches
TCPServer Class Reference

#include <tcp_server.hpp>

Public Member Functions

 TCPServer (size_t maxConnections)
 Construct a new TCPServer object.
 
 TCPServer (const TCPServer &)=delete
 
TCPServeroperator= (const TCPServer &)=delete
 
 TCPServer (TCPServer &&)=delete
 
 ~TCPServer ()
 
void setOnConnect (std::function< void(std::shared_ptr< TCPSocket >)> const &onConnect)
 Set the function to call when a new client connects.
 
void setOnDisconnect (std::function< void(std::shared_ptr< TCPSocket >)> const &onDisconnect)
 Set the function to call when a client disconnects.
 
void setOnData (std::function< void(std::shared_ptr< TCPSocket >, std::string &)> const &onData)
 Set the function to call when data is received from a client.
 
bool start (const std::string &ip, uint16_t port, int listen_backlog=1)
 Start the server.
 
void stop ()
 Stop the server.
 

Constructor & Destructor Documentation

◆ TCPServer() [1/3]

TCPServer::TCPServer ( size_t maxConnections)
explicit

Construct a new TCPServer object.

Parameters
maxConnectionsThe maximum number of clients the server can handle. Will be capped at HARD_CONNECTION_LIMIT.

◆ TCPServer() [2/3]

TCPServer::TCPServer ( const TCPServer & )
delete

◆ TCPServer() [3/3]

TCPServer::TCPServer ( TCPServer && )
delete

◆ ~TCPServer()

TCPServer::~TCPServer ( )

Member Function Documentation

◆ operator=()

TCPServer & TCPServer::operator= ( const TCPServer & )
delete

◆ setOnConnect()

void TCPServer::setOnConnect ( std::function< void(std::shared_ptr< TCPSocket >)> const & onConnect)

Set the function to call when a new client connects.

Parameters
onConnectThe function to call when a new client connects.

◆ setOnData()

void TCPServer::setOnData ( std::function< void(std::shared_ptr< TCPSocket >, std::string &)> const & onData)

Set the function to call when data is received from a client.

Parameters
onDataThe function to call when data is received from a client.

◆ setOnDisconnect()

void TCPServer::setOnDisconnect ( std::function< void(std::shared_ptr< TCPSocket >)> const & onDisconnect)

Set the function to call when a client disconnects.

Parameters
onDisconnectThe function to call when a client disconnects.

◆ start()

bool TCPServer::start ( const std::string & ip,
uint16_t port,
int listen_backlog = 1 )

Start the server.

Parameters
ipThe IP address to listen on, or an empty string to listen on all interfaces.
portThe port to listen on.
listen_backlogThe maximum number of pending connections.
Returns
true on success, false on failure.

◆ stop()

void TCPServer::stop ( )

Stop the server.


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