#include <TCPServer.h>
◆ TCPServer()
| TCPServer::TCPServer |
( |
int |
port, |
|
|
ILogger & |
logger |
|
) |
| |
Construct a TCPServer
- Parameters
-
| port | Port to open the server to |
| logger | used to log info of the server |
◆ ~TCPServer()
| TCPServer::~TCPServer |
( |
| ) |
|
◆ close()
| void TCPServer::close |
( |
| ) |
|
|
overridevirtual |
Terminate a client connection.
Implements ITCPServer.
◆ init()
Create and bind the socket.
◆ isClientConnected()
| bool TCPServer::isClientConnected |
( |
| ) |
|
|
overridevirtual |
See if the server has a client connected
- Returns
- true if the TCP server has a client connected.
Implements ITCPServer.
◆ listen()
| void TCPServer::listen |
( |
| ) |
|
|
virtual |
Start listening for incoming client connections and accept one client. This is blocking until a client connects.
Implements ITCPServer.
◆ onConnect()
| void TCPServer::onConnect |
( |
std::function< void()> |
hook | ) |
|
|
overridevirtual |
Register a callback to be run when a TCP connection is established with a client HiveMind
- Parameters
-
| hook | The function to be run |
Implements ITCPServer.
◆ onDisconnect()
| void TCPServer::onDisconnect |
( |
std::function< void()> |
hook | ) |
|
|
overridevirtual |
Register a callback to be run as soon as the TCP Server notices that the connection was lost.
- Parameters
-
| hook | The function to be run |
Implements ITCPServer.
◆ receive()
| bool TCPServer::receive |
( |
uint8_t * |
data, |
|
|
uint16_t |
length |
|
) |
| |
|
overridevirtual |
Read data from socket.
- Parameters
-
| data | The buffer on which the incoming data will be written. |
| length | The length of the provided buffer. |
- Returns
- The length of the data read.
Implements ITCPServer.
◆ send()
| bool TCPServer::send |
( |
const uint8_t * |
data, |
|
|
uint16_t |
length |
|
) |
| |
|
overridevirtual |
Send some data to the client.
- Parameters
-
| data | The buffer containing the data to send. |
| length | The length of the data on the buffer. |
Implements ITCPServer.
◆ m_address
| struct sockaddr_in TCPServer::m_address |
|
private |
◆ m_addressLength
| int TCPServer::m_addressLength |
|
private |
◆ m_clientFd
| int TCPServer::m_clientFd |
|
private |
◆ m_isClientConnected
| bool TCPServer::m_isClientConnected = false |
|
private |
◆ m_logger
| ILogger& TCPServer::m_logger |
|
private |
◆ m_onConnect
| std::function<void()> TCPServer::m_onConnect |
|
private |
◆ m_onDisonnect
| std::function<void()> TCPServer::m_onDisonnect |
|
private |
◆ m_port
◆ m_serverFd
| int TCPServer::m_serverFd |
|
private |
The documentation for this class was generated from the following files: