asio C++ library

PrevUpHomeNext
basic_socket_acceptor::accept (11 of 12 overloads)

Accept a new connection.

Protocol::socket accept(
    asio::io_context & io_context,
    endpoint_type & peer_endpoint);

This function is used to accept a new connection from a peer. The function call will block until a new connection has been accepted successfully or an error occurs.

This overload requires that the Protocol template parameter satisfy the AcceptableProtocol type requirements.

Parameters

io_context

The io_context object to be used for the newly accepted socket.

peer_endpoint

An endpoint object into which the endpoint of the remote peer will be written.

Return Value

A socket object representing the newly accepted connection.

Exceptions

asio::system_error

Thrown on failure.

Example
asio::ip::tcp::acceptor acceptor(io_context);
...
asio::ip::tcp::endpoint endpoint;
asio::ip::tcp::socket socket(
    acceptor.accept(io_context2, endpoint));

PrevUpHomeNext