Async 1.8.0
Async::TcpServerBase Class Referenceabstract

The base class for creating a TCP server. More...

#include <AsyncTcpServerBase.h>

Inheritance diagram for Async::TcpServerBase:
Async::TcpServer< ConT >

Public Member Functions

 TcpServerBase (const std::string &port_str, const Async::IpAddress &bind_ip)
 Default constuctor.
 
virtual ~TcpServerBase (void)
 Destructor.
 
int numberOfClients (void)
 Get the number of clients that is connected to the server.
 
TcpConnectiongetClient (unsigned int index)
 Get the client object pointer from the server.
 
int writeAll (const void *buf, int count)
 Write data to all connected clients.
 
int writeOnly (TcpConnection *con, const void *buf, int count)
 Send data only to the given client.
 
int writeExcept (TcpConnection *con, const void *buf, int count)
 Send data to all connected clients except the given client.
 
void setSslContext (SslContext &ctx)
 Set the SSL context for all new connections.
 
void setConnectionThrottling (unsigned bucket_max, float bucket_inc, int inc_interval_ms)
 Enable connection throttling.
 

Protected Member Functions

virtual void createConnection (int sock, const IpAddress &remote_addr, uint16_t remote_port)=0
 
void addConnection (TcpConnection *con)
 
void removeConnection (TcpConnection *con)
 
virtual void emitClientConnected (TcpConnection *con)=0
 

Detailed Description

The base class for creating a TCP server.

Author
Tobias Blomberg
Date
2003-12-07

Definition at line 115 of file AsyncTcpServerBase.h.

Constructor & Destructor Documentation

◆ TcpServerBase()

Async::TcpServerBase::TcpServerBase ( const std::string & port_str,
const Async::IpAddress & bind_ip )

Default constuctor.

Parameters
port_strA port number or service name to listen to
bind_ipThe IP to bind the server to

◆ ~TcpServerBase()

virtual Async::TcpServerBase::~TcpServerBase ( void )
virtual

Destructor.

Member Function Documentation

◆ addConnection()

void Async::TcpServerBase::addConnection ( TcpConnection * con)
protected

◆ createConnection()

virtual void Async::TcpServerBase::createConnection ( int sock,
const IpAddress & remote_addr,
uint16_t remote_port )
protectedpure virtual

Implemented in Async::TcpServer< ConT >.

◆ emitClientConnected()

virtual void Async::TcpServerBase::emitClientConnected ( TcpConnection * con)
protectedpure virtual

Implemented in Async::TcpServer< ConT >.

◆ getClient()

TcpConnection * Async::TcpServerBase::getClient ( unsigned int index)

Get the client object pointer from the server.

Parameters
indexThe wanted client by number 0 - numberOfClients()-1
Returns
The TcpConnection pointer to the client (zero if not found)

Referenced by Async::TcpServer< ConT >::getClient().

◆ numberOfClients()

int Async::TcpServerBase::numberOfClients ( void )

Get the number of clients that is connected to the server.

Returns
The number of connected clients
Examples
AsyncFramedTcpServer_demo.cpp, and AsyncTcpServer_demo.cpp.

◆ removeConnection()

void Async::TcpServerBase::removeConnection ( TcpConnection * con)
protected

◆ setConnectionThrottling()

void Async::TcpServerBase::setConnectionThrottling ( unsigned bucket_max,
float bucket_inc,
int inc_interval_ms )

Enable connection throttling.

Parameters
bucket_maxThe size of the bucket
bucket_incHow much to add to the bucket on each tick
inc_interval_msHow often, in milliseconds, to apply bucket_inc

Use this function to put a limit on the connection rate for each IP address. The "token bucket" algorithm is used to throttle connection flooding. The connection will be accepted but the communication will be blocked until a token is available in the bucket.

Example: bucket_max=5, bucket_inc=0.1, inc_interval_ms=1000 With those settings five connections from an IP will be accepted without delay. Each second (1000ms) the bucket for the IP will be filled with 0.1 tokens so it will take ten seconds until another connection will be allowed to communicate. If no additional connections for the IP are initiated, the bucket will fill to five tokens again efter 50 seconds and we are back to where we started.

◆ setSslContext()

void Async::TcpServerBase::setSslContext ( SslContext & ctx)

Set the SSL context for all new connections.

Parameters
ctxThe SSL context to set

Call this function to set an SSL context that is applied automatically for all client connections. If this is set up in the server all that need to be done, in a client connection after it is established, is to enable SSL by calling enableSsl() on the connection object.

NOTE: The context object is neither copied nor managed by this class so it must be persisted by the caller for as long as this class or any connections live. It is also the responsibility for the caller to delete the context object when it fills no purpose anymore.

◆ writeAll()

int Async::TcpServerBase::writeAll ( const void * buf,
int count )

Write data to all connected clients.

Parameters
bufThe data buffer
countThe number of bytes in the data buffer
Returns
The number of bytes sent
Examples
AsyncTcpServer_demo.cpp.

◆ writeExcept()

int Async::TcpServerBase::writeExcept ( TcpConnection * con,
const void * buf,
int count )

Send data to all connected clients except the given client.

Parameters
conThe TcpConnection object not to send to
bufThe data buffer
countThe number of bytes in the data buffer
Returns
The number of bytes sent
Examples
AsyncTcpServer_demo.cpp.

◆ writeOnly()

int Async::TcpServerBase::writeOnly ( TcpConnection * con,
const void * buf,
int count )

Send data only to the given client.

Parameters
conThe TcpConnection object to send to
bufThe data buffer
countThe number of bytes in data buffer
Returns
The number of bytes sent
Examples
AsyncTcpServer_demo.cpp.

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