-
Notifications
You must be signed in to change notification settings - Fork 133
TCP Server
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.
typedef std::function<bool(const std::shared_ptr<tcp_client>&)> on_new_connection_callback_t;
Type | Description |
---|---|
tcp_client& |
Reference to the tcp_client that wishes to connect |
bool |
Return value. Tells whether the client connection request should be accepted or declined |
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).
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).
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.
void stop(void);
Description
Disconnect the tcp_server if it was currently running.
Parameters
None
Return value
Returns nothing.
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.
Need more information? Contact me.