![]() |
Ember
|
Single-client TCP server for receiving behavior tree data from monitored applications. More...
#include <TCPServer.h>
Public Types | |
| using | MessageCallback = std::function<void(const Network::MessageFrame &)> |
| Callback invoked when a message is received from the client. | |
| using | ConnectCallback = std::function<void(const std::string &address)> |
| Callback invoked when a client connects. | |
| using | DisconnectCallback = std::function<void()> |
| Callback invoked when the client disconnects. | |
Public Member Functions | |
| TCPServer () | |
| ~TCPServer () | |
| bool | Start (uint16_t port) |
| Starts the server listening on the given port. Returns true on success. | |
| void | Stop () |
| Stops the server and disconnects any client. | |
| bool | IsRunning () const |
| Returns true if the server is listening. | |
| bool | IsClientConnected () const |
| Returns true if a client is currently connected. | |
| std::string | GetClientAddress () const |
| Returns the connected client's address string. | |
| std::string | GetClientName () const |
| Returns the client's display name. | |
| void | SetClientName (const std::string &name) |
| Sets the client's display name. | |
| uint16_t | GetPort () const |
| Returns the port the server is listening on. | |
| void | SetMessageCallback (MessageCallback cb) |
| Sets the callback for incoming messages. | |
| void | SetConnectCallback (ConnectCallback cb) |
| Sets the callback for client connections. | |
| void | SetDisconnectCallback (DisconnectCallback cb) |
| Sets the callback for client disconnections. | |
| void | Poll () |
| Processes pending I/O (accept, read). Call periodically from the main loop. | |
| bool | Send (const Network::MessageFrame &frame) |
| Sends a message frame to the connected client. Returns true on success. | |
| void | DisconnectClient () |
| Disconnects the current client without stopping the server. | |
Private Member Functions | |
| void | AcceptConnection () |
| void | ReadFromClient () |
| bool | SetNonBlocking (int socket) |
Private Attributes | |
| int | m_serverSocket = -1 |
| int | m_clientSocket = -1 |
| std::string | m_clientAddress |
| std::string | m_clientName |
| uint16_t | m_port = 0 |
| std::vector< uint8_t > | m_recvBuffer |
| MessageCallback | m_messageCallback |
| ConnectCallback | m_connectCallback |
| DisconnectCallback | m_disconnectCallback |
Single-client TCP server for receiving behavior tree data from monitored applications.
Definition at line 14 of file TCPServer.h.
| using Ember::Monitor::TCPServer::ConnectCallback = std::function<void(const std::string &address)> |
Callback invoked when a client connects.
Definition at line 19 of file TCPServer.h.
| using Ember::Monitor::TCPServer::DisconnectCallback = std::function<void()> |
Callback invoked when the client disconnects.
Definition at line 21 of file TCPServer.h.
| using Ember::Monitor::TCPServer::MessageCallback = std::function<void(const Network::MessageFrame &)> |
Callback invoked when a message is received from the client.
Definition at line 17 of file TCPServer.h.
| Ember::Monitor::TCPServer::TCPServer | ( | ) |
Definition at line 15 of file TCPServer.cpp.
| Ember::Monitor::TCPServer::~TCPServer | ( | ) |
Definition at line 17 of file TCPServer.cpp.
|
private |
Definition at line 96 of file TCPServer.cpp.
| void Ember::Monitor::TCPServer::DisconnectClient | ( | ) |
Disconnects the current client without stopping the server.
Definition at line 82 of file TCPServer.cpp.
|
inline |
Returns the connected client's address string.
Definition at line 36 of file TCPServer.h.
|
inline |
Returns the client's display name.
Definition at line 38 of file TCPServer.h.
|
inline |
Returns the port the server is listening on.
Definition at line 42 of file TCPServer.h.
|
inline |
Returns true if a client is currently connected.
Definition at line 33 of file TCPServer.h.
|
inline |
Returns true if the server is listening.
Definition at line 31 of file TCPServer.h.
| void Ember::Monitor::TCPServer::Poll | ( | ) |
Processes pending I/O (accept, read). Call periodically from the main loop.
Definition at line 173 of file TCPServer.cpp.
|
private |
Definition at line 125 of file TCPServer.cpp.
| bool Ember::Monitor::TCPServer::Send | ( | const Network::MessageFrame & | frame | ) |
Sends a message frame to the connected client. Returns true on success.
Definition at line 209 of file TCPServer.cpp.
|
inline |
Sets the client's display name.
Definition at line 40 of file TCPServer.h.
|
inline |
Sets the callback for client connections.
Definition at line 47 of file TCPServer.h.
|
inline |
Sets the callback for client disconnections.
Definition at line 49 of file TCPServer.h.
|
inline |
Sets the callback for incoming messages.
Definition at line 45 of file TCPServer.h.
|
private |
Definition at line 19 of file TCPServer.cpp.
| bool Ember::Monitor::TCPServer::Start | ( | uint16_t | port | ) |
Starts the server listening on the given port. Returns true on success.
Definition at line 27 of file TCPServer.cpp.
| void Ember::Monitor::TCPServer::Stop | ( | ) |
Stops the server and disconnects any client.
Definition at line 72 of file TCPServer.cpp.
|
private |
Definition at line 67 of file TCPServer.h.
|
private |
Definition at line 68 of file TCPServer.h.
|
private |
Definition at line 66 of file TCPServer.h.
|
private |
Definition at line 74 of file TCPServer.h.
|
private |
Definition at line 75 of file TCPServer.h.
|
private |
Definition at line 73 of file TCPServer.h.
|
private |
Definition at line 69 of file TCPServer.h.
|
private |
Definition at line 71 of file TCPServer.h.
|
private |
Definition at line 65 of file TCPServer.h.