Class Connection#

Class Documentation#

class Connection#

Class to manage a single client connection.

Public Types

using conn_t = boost::beast::websocket::stream<boost::beast::tcp_stream>#

Type alias for the low level stream.

using handler_t = std::function<void(Connection&)>#

Type alias for a basic callback.

using msg_handler_t = std::function<void(Connection&, const uint8_t *data, size_t size)>#

Type alias for a messenger handler callback.

Public Functions

Connection(std::unique_ptr<conn_t> conn, msg_handler_t on_message, handler_t on_close)#

Connection constructor.

Parameters:
  • conn – - Low level stream

  • on_message – - Message handler callback

  • on_close – - On close callback

~Connection()#
void send(const uint8_t *data, size_t len)#

Send a message to the client.

Parameters:
  • data – - The message buffer to send.

  • len – - Number of bytes to send.

void onMessage(msg_handler_t on_message)#

Set the message handler.

Parameters:

on_message – - The message handler

void onClose(handler_t on_close)#

Set the close handler.

Parameters:

on_close – - The close handler