Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

TCP Server

Simon Ninon edited this page Dec 12, 2016 · 11 revisions

tacopie::tcp_server is the class providing TCP Server features.

The tcp_client works entirely asynchronously, waiting for the io_service to notify whenever a new client wished to connect.

Typedefs

on_new_connection_callback_t

  typedef std::function<bool(const std::shared_ptr<tcp_client>&)> on_new_connection_callback_t;
Type Description
const std::shared_ptr<tcp_client>& Shared pointer to the tcp_client that wishes to connect
bool Return value. Tells whether the client connection request should be accepted or declined

Methods

operator==

  bool operator==(const tcp_server& rhs) const;

Description

Comparison operator overload.

Parameters

Type Description
const tcp_server& Reference to the tcp_server to compare with

Return value

Returns true when the underlying sockets are the same (same file descriptor and socket type).

operator!=

  bool operator!=(const tcp_server& rhs) const;

Description

Comparison operator overload.

Parameters

Type Description
const tcp_server& Reference to the tcp_server to compare with

Return value

Returns true when the underlying sockets are different (different file descriptor or socket type).

start

  void start(const std::string& addr, std::uint32_t port, const on_new_connection_callback_t& callback = nullptr);

Description

Start the tcp_server at the given host and port.

Parameters

Type Description
const std::string& Hostname
`std::uint32_t Port
const on_new_connection_callback_t& Callback to call whenever a new client requests to connect

Return value

Returns nothing but throws in case of initialization & connection failure.

stop

  void stop(void);

Description

Disconnect the tcp_server if it was currently running.

Parameters

None

Return value

Returns nothing.

is_running

  bool is_running(void) const;

Description

Indicates whether the tcp_server is running or not

Parameters

None

Return value

Returns true if the tcp_server is running.

Clone this wiki locally