Go to the documentation of this file.
29 #ifndef UR_CLIENT_LIBRARY_TCP_SERVER_H_INCLUDED
30 #define UR_CLIENT_LIBRARY_TCP_SERVER_H_INCLUDED
71 explicit TCPServer(
const int port,
const size_t max_num_tries = 0,
72 const std::chrono::milliseconds reconnection_time = std::chrono::seconds(1));
134 bool write(
const socket_t fd,
const uint8_t* buf,
const size_t buf_len,
size_t& written);
159 void bind(
const size_t max_num_tries,
const std::chrono::milliseconds reconnection_time);
200 #endif // ifndef UR_CLIENT_LIBRARY_TCP_SERVER_H_INCLUDED
void shutdown()
Shut down the event listener thread. After calling this, no events will be handled anymore,...
void start()
Start event handling.
static const int INPUT_BUFFER_SIZE
void handleConnect()
Handles connection events.
char input_buffer_[INPUT_BUFFER_SIZE]
uint32_t max_clients_allowed_
std::function< void(const socket_t, char *buffer, int nbytesrecv)> message_callback_
std::atomic< bool > keep_running_
void setMaxClientsAllowed(const uint32_t &max_clients_allowed)
Set the maximum number of clients allowed to connect to this server.
std::vector< socket_t > client_fds_
void setDisconnectCallback(std::function< void(const socket_t)> func)
This callback will be triggered on clients disconnecting from the server.
uint32_t getMaxClientsAllowed() const
Get the maximum number of clients allowed to connect to this server.
void setMessageCallback(std::function< void(const socket_t, char *, int)> func)
This callback will be triggered on messages received on the socket.
Wrapper class for a TCP socket server.
void readData(const socket_t fd)
read data from socket
bool write(const socket_t fd, const uint8_t *buf, const size_t buf_len, size_t &written)
Writes to a client.
void handleDisconnect(const socket_t fd)
std::thread worker_thread_
void spin()
Event handler. Blocks until activity on any client or connection attempt.
void bind(const size_t max_num_tries, const std::chrono::milliseconds reconnection_time)
void worker()
Runs spin() as long as keep_running_ is set to true.
std::function< void(const socket_t)> disconnect_callback_
std::function< void(const socket_t)> new_connection_callback_
std::atomic< socket_t > listen_fd_
void setConnectCallback(std::function< void(const socket_t)> func)
This callback will be triggered on clients connecting to the server.
ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Mon May 26 2025 02:35:58