The base class for creating a TCP server.
More...
#include <AsyncTcpServerBase.h>
The base class for creating a TCP server.
- Author
- Tobias Blomberg
- Date
- 2003-12-07
Definition at line 115 of file AsyncTcpServerBase.h.
◆ TcpServerBase()
Async::TcpServerBase::TcpServerBase |
( |
const std::string & | port_str, |
|
|
const Async::IpAddress & | bind_ip ) |
Default constuctor.
- Parameters
-
port_str | A port number or service name to listen to |
bind_ip | The IP to bind the server to |
◆ ~TcpServerBase()
virtual Async::TcpServerBase::~TcpServerBase |
( |
void | | ) |
|
|
virtual |
◆ addConnection()
◆ createConnection()
virtual void Async::TcpServerBase::createConnection |
( |
int | sock, |
|
|
const IpAddress & | remote_addr, |
|
|
uint16_t | remote_port ) |
|
protectedpure virtual |
◆ emitClientConnected()
virtual void Async::TcpServerBase::emitClientConnected |
( |
TcpConnection * | con | ) |
|
|
protectedpure virtual |
◆ getClient()
TcpConnection * Async::TcpServerBase::getClient |
( |
unsigned int | index | ) |
|
◆ numberOfClients()
int Async::TcpServerBase::numberOfClients |
( |
void | | ) |
|
◆ 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_max | The size of the bucket |
bucket_inc | How much to add to the bucket on each tick |
inc_interval_ms | How 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
-
ctx | The 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
-
buf | The data buffer |
count | The 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
-
con | The TcpConnection object not to send to |
buf | The data buffer |
count | The 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
-
con | The TcpConnection object to send to |
buf | The data buffer |
count | The 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: