#include <BaseTCPServer.h>
|
template<typename DataT > |
static int | sendBytes (SOCKET clientSocket, const DataT *const data, int size) |
|
template<typename DataT > |
static int | receiveBytes (SOCKET clientSocket, DataT *const data, int size) |
|
◆ BaseTCPServer()
web::BaseTCPServer::BaseTCPServer |
( |
std::string_view | port, |
|
|
std::string_view | ip = "0.0.0.0", |
|
|
DWORD | timeout = 0, |
|
|
bool | multiThreading = true, |
|
|
u_long | listenSocketBlockingMode = 0, |
|
|
bool | freeDLL = true ) |
- Parameters
-
port | Server's port |
ip | Server's ip |
timeout | recv function timeout in milliseconds, 0 wait for upcoming data |
multiThreading | Each client in separate thread |
listenSocketBlockingMode | Blocking mode for listen socket (0 - blocking, non 0 - non blocking) |
freeDLL | Unload Ws2_32.dll in destructor(Windows only parameter) |
◆ ~BaseTCPServer()
web::BaseTCPServer::~BaseTCPServer |
( |
| ) |
|
|
virtual |
◆ autoCloseSocket()
bool web::BaseTCPServer::autoCloseSocket |
( |
| ) |
const |
|
protectedvirtual |
Automatically close socket after clientConnection in cleanup function.
- Returns
◆ clientConnection()
virtual void web::BaseTCPServer::clientConnection |
( |
const std::string & | ip, |
|
|
SOCKET | clientSocket, |
|
|
sockaddr | address, |
|
|
std::function< void()> & | cleanup ) |
|
protectedpure virtual |
Serving each client connection.
- Parameters
-
ip | Client IP address |
clientSocket | Client socket |
address | Structure used to store most addresses. |
cleanup | Move this function if you want made cleanup by yourself |
◆ createListenSocket()
void web::BaseTCPServer::createListenSocket |
( |
| ) |
|
|
protected |
◆ getClientIpV4()
string web::BaseTCPServer::getClientIpV4 |
( |
sockaddr | address | ) |
|
|
static |
Get client IP address.
- Parameters
-
- Returns
◆ getClientPortV4()
uint16_t web::BaseTCPServer::getClientPortV4 |
( |
sockaddr | address | ) |
|
|
static |
Get client port.
- Parameters
-
- Returns
◆ getClients()
vector< pair< string, vector< SOCKET > > > web::BaseTCPServer::getClients |
( |
| ) |
const |
Get all clients ip - sockets.
- Returns
◆ getIp()
string_view web::BaseTCPServer::getIp |
( |
| ) |
const |
Initial passed IP.
- Returns
◆ getNumberOfClients()
size_t web::BaseTCPServer::getNumberOfClients |
( |
| ) |
const |
Number of IP addresses.
- Returns
◆ getNumberOfConnections()
size_t web::BaseTCPServer::getNumberOfConnections |
( |
| ) |
const |
Number of sockets(each IP address may have few sockets)
- Returns
◆ getPort()
string_view web::BaseTCPServer::getPort |
( |
| ) |
const |
Initial passed port.
- Returns
◆ getServerIpV4()
string web::BaseTCPServer::getServerIpV4 |
( |
| ) |
const |
Get server IP address.
- Returns
◆ getServerPortV4()
uint16_t web::BaseTCPServer::getServerPortV4 |
( |
| ) |
const |
◆ getVersion()
string web::BaseTCPServer::getVersion |
( |
| ) |
|
|
static |
◆ isAcceptedSocketsInBlockingMode()
bool web::BaseTCPServer::isAcceptedSocketsInBlockingMode |
( |
| ) |
const |
Is client's socket in blocking mode.
- Returns
◆ isListenSocketInBlockingMode()
bool web::BaseTCPServer::isListenSocketInBlockingMode |
( |
| ) |
const |
Is server's listen socket in blocking mode.
- Returns
◆ isServerRunning()
bool web::BaseTCPServer::isServerRunning |
( |
| ) |
const |
Is server accept new connections.
- Returns
◆ kick()
void web::BaseTCPServer::kick |
( |
const std::string & | ip | ) |
|
|
virtual |
Kick specific client.
- Parameters
-
◆ kickAll()
void web::BaseTCPServer::kickAll |
( |
| ) |
|
|
virtual |
◆ onConnectionReceive()
void web::BaseTCPServer::onConnectionReceive |
( |
SOCKET | clientSocket, |
|
|
sockaddr | address ) |
|
protectedvirtual |
◆ onInvalidConnectionReceive()
void web::BaseTCPServer::onInvalidConnectionReceive |
( |
| ) |
|
|
protectedvirtual |
◆ receiveBytes()
template<typename DataT >
int web::BaseTCPServer::receiveBytes |
( |
SOCKET | clientSocket, |
|
|
DataT *const | data, |
|
|
int | size ) |
|
staticprotected |
◆ receiveConnections()
void web::BaseTCPServer::receiveConnections |
( |
const std::function< void()> & | onStartServer, |
|
|
std::exception ** | outException ) |
|
protectedvirtual |
◆ sendBytes()
template<typename DataT >
int web::BaseTCPServer::sendBytes |
( |
SOCKET | clientSocket, |
|
|
const DataT *const | data, |
|
|
int | size ) |
|
staticprotected |
◆ serve()
void web::BaseTCPServer::serve |
( |
std::string | ip, |
|
|
SOCKET | clientSocket, |
|
|
sockaddr | address ) |
|
protectedvirtual |
◆ setAcceptedSocketsBlockingMode()
void web::BaseTCPServer::setAcceptedSocketsBlockingMode |
( |
bool | block | ) |
|
Set blocking mode for all connected sockets.
- Parameters
-
◆ start()
void web::BaseTCPServer::start |
( |
bool | wait = false, |
|
|
const std::function< void()> & | onStartServer = []() {}, |
|
|
std::exception ** | outException = nullptr ) |
|
virtual |
Start server in separate thread.
- Parameters
-
wait | Wait server serving in current thread |
onStartServer | Call function before accept first connection |
◆ stop()
void web::BaseTCPServer::stop |
( |
bool | wait = true | ) |
|
|
virtual |
Stop receiving new connections.
- Parameters
-
wait | Wait all clients tasks |
◆ blockingMode
u_long web::BaseTCPServer::blockingMode |
|
protected |
0 for blocking, non 0 for non blocking
◆ data
ClientData web::BaseTCPServer::data |
|
protected |
◆ freeDLL
bool web::BaseTCPServer::freeDLL |
|
protected |
◆ handle
std::future<void> web::BaseTCPServer::handle |
|
protected |
◆ ip
std::string web::BaseTCPServer::ip |
|
protected |
◆ ipV4Size
size_t web::BaseTCPServer::ipV4Size = 16 |
|
staticconstexpr |
◆ isRunning
bool web::BaseTCPServer::isRunning |
|
protected |
◆ listenSocket
SOCKET web::BaseTCPServer::listenSocket |
|
protected |
◆ listenSocketBlockingMode
u_long web::BaseTCPServer::listenSocketBlockingMode |
|
protected |
0 for blocking, non 0 for non blocking
◆ multiThreading
const bool web::BaseTCPServer::multiThreading |
|
protected |
◆ port
std::string web::BaseTCPServer::port |
|
protected |
◆ timeout
DWORD web::BaseTCPServer::timeout |
|
protected |
The documentation for this class was generated from the following files: