PL::TcpServer class
-
class TcpServer : public PL::NetworkServer
TCP server class.
Public Functions
-
TcpServer(uint16_t port)
Creates a TCP server.
- Parameters:
port – port
-
virtual esp_err_t Lock(TickType_t timeout = portMAX_DELAY) override
Locks the object.
- Parameters:
timeout – timeout in FreeRTOS ticks
- Returns:
error code
-
virtual esp_err_t Unlock() override
Unlocks the object.
- Returns:
error code
-
virtual esp_err_t Enable() override
Enables the server.
- Returns:
error code
-
virtual esp_err_t Disable() override
Disables the server.
- Returns:
error code
-
esp_err_t EnableNagleAlgorithm()
Enables the Nagle’s algorithm.
- Returns:
error code
-
esp_err_t DisableNagleAlgorithm()
Disables the Nagle’s algorithm.
- Returns:
error code
-
esp_err_t EnableKeepAlive()
Enables the keep-alive packets.
- Returns:
error code
-
esp_err_t DisableKeepAlive()
Disables the keep-alive packets.
- Returns:
error code
-
virtual bool IsEnabled() override
Checks if the server is enabled.
- Returns:
true if the server is enabled
-
virtual uint16_t GetPort() override
Gets listening port.
- Returns:
port
-
virtual esp_err_t SetPort(uint16_t port) override
Sets listening port.
- Parameters:
port – port
- Returns:
error code
-
virtual size_t GetMaxNumberOfClients() override
Gets the maximum number of server clients.
- Returns:
number of clients
-
virtual esp_err_t SetMaxNumberOfClients(size_t maxNumberOfClients) override
Sets the maximum number of server clients.
- Parameters:
maxNumberOfClients – number of clients
- Returns:
error code
-
std::vector<std::shared_ptr<NetworkStream>> GetClientStreams()
Gets the connected client streams.
- Returns:
client streams
-
esp_err_t SetTaskParameters(const TaskParameters &taskParameters)
Sets the server task parameters.
- Parameters:
taskParameters – task parameters
- Returns:
error code
-
esp_err_t SetKeepAliveIdleTime(int seconds)
Sets the idle time before the keep-alive packets are sent.
- Parameters:
seconds – time in seconds
- Returns:
error code
-
esp_err_t SetKeepAliveInterval(int seconds)
Sets the keep-alive packet interval.
- Parameters:
seconds – interval in seconds
- Returns:
error code
-
esp_err_t SetKeepAliveCount(int count)
Sets the number of the keep-alive packets.
- Parameters:
count – number of packets
- Returns:
error code
-
std::string GetName()
Gets the server name.
- Returns:
name
-
void SetName(const std::string &name)
Sets the server name.
- Parameters:
name – name
Public Members
-
Event<TcpServer, NetworkStream&> clientConnectedEvent
Client connected event.
-
Event<TcpServer, NetworkStream&> clientDisconnectedEvent
Client disconnected event.
Public Static Attributes
-
static const TaskParameters defaultTaskParameters
Default server task parameters.
-
static const int defaultMaxNumberOfClients = 1
Default maximum number of server clients.
-
static const int defaultKeepAliveIdleTime = 7200
Default idle time before the keep-alive packets are sent in seconds.
-
static const int defaultKeepAliveInterval = 75
Default keep-alive packet interval in seconds.
-
static const int defaultKeepAliveCount = 9
Default number of the keep-alive packets.
Protected Functions
-
virtual esp_err_t HandleRequest(NetworkStream &clientStream) = 0
Handles the TCP client request.
- Parameters:
clientStream – client stream
- Returns:
error code
-
TcpServer(uint16_t port)