A TCP server that accepts many clients and exchanges length-prefixed messages with them.
More...
|
| | Server (std::uint16_t port, std::function< void()> callback, bool keepAliveByHeartBeat=true, bool sendHeartBeats=false, LoggerConfig loggerConfig={}) |
| | Creates a server bound to a port on all IPv4 interfaces. Clients are not accepted until start() is called.
|
|
| ~Server () |
| | Stops the server (see stop()) and releases its resources.
|
|
void | start () |
| | Starts accepting clients on the I/O thread.
|
|
void | stop () |
| | Stops accepting, closes every connection, wakes any thread blocked in receive() and joins the I/O thread.
|
| std::optional< acsf::Message > | receive () |
| | Blocks until a message arrives from any client.
|
| void | send (uint64_t id, std::string body) |
| | Queues a message to be sent to one client.
|
| void | setTimeout (TimeoutType type, std::chrono::milliseconds duration) |
| | Changes one of the timeouts. Timeouts are shared by every server and client in the program.
|
A TCP server that accepts many clients and exchanges length-prefixed messages with them.
The server runs its own I/O thread. Every client gets a numeric id (0, 1, 2, ...) in connection order. Incoming messages from all clients arrive through receive(), tagged with the sender's id in Message::isFrom. Reply to a specific client with send().
while (auto msg = server.receive()) {
server.send(msg->isFrom, "echo: " + msg->payload);
}
server.stop();
A TCP server that accepts many clients and exchanges length-prefixed messages with them.
Definition server.h:31
void start()
Starts accepting clients on the I/O thread.
Definition server.h:110
- Examples
- main_example.cpp.