MeVisLab Toolbox Reference
asio::TcpAcceptor Class Reference

A TCP acceptor listening on a given port and interface address. More...

#include <TcpAcceptor.h>

Public Member Functions

 TcpAcceptor (std::shared_ptr< Context > context, const std::string &address, const unsigned short port)
 
template<typename AcceptHandler >
void async_accept (TcpSocket &candidate, AcceptHandler &&handler)
 
unsigned short port () const
 
void cancel ()
 
void close ()
 

Detailed Description

A TCP acceptor listening on a given port and interface address.

Synopsis:

auto context = std::make_shared<asio::Context>();
asio::TcpAcceptor acceptor{ context, "127.0.0.1", 8080 };
asio::TcpSocket socket{ context };
acceptor.async_accept(socket, [] (const asio::ErrorCode& ec) {
if (!ec) {
// Successfully accepted incoming connection
}
});
context->run();
A TCP acceptor listening on a given port and interface address.
Definition TcpAcceptor.h:40
A TCP socket class implementing the asio::Socket interface.
Definition TcpSocket.h:39
boost::system::error_code ErrorCode
Definition ErrorCodes.h:13

This is quite low level, have a look at asio::TcpAcceptorSession for creating a TCP server.

Definition at line 39 of file TcpAcceptor.h.

Constructor & Destructor Documentation

◆ TcpAcceptor()

asio::TcpAcceptor::TcpAcceptor ( std::shared_ptr< Context > context,
const std::string & address,
const unsigned short port )

Member Function Documentation

◆ async_accept()

template<typename AcceptHandler >
void asio::TcpAcceptor::async_accept ( TcpSocket & candidate,
AcceptHandler && handler )
inline

Definition at line 46 of file TcpAcceptor.h.

References mlrange_cast().

◆ cancel()

void asio::TcpAcceptor::cancel ( )

◆ close()

void asio::TcpAcceptor::close ( )

◆ port()

unsigned short asio::TcpAcceptor::port ( ) const

The documentation for this class was generated from the following file: