xtd 0.2.0
Loading...
Searching...
No Matches

◆ end_accept()

socket xtd::net::sockets::socket::end_accept ( xtd::sptr< xtd::iasync_result async_result)

Asynchronously accepts an incoming connection attempt and creates a new xtd::net::sockets::socket::socket to handle remote host communication.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Returns
A xtd::net::sockets::socket::socket to handle communication with the remote host.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
xtd::net::sockets::socket::end_accept completes a call to xtd::net::sockets::socket::begin_accept. Before calling xtd::net::sockets::socket::begin_accept, you need to create a callback method that implements the xtd::async_callback delegate. This callback method executes in a separate thread, and is called by the system after the xtd::net::sockets::socket::begin_accept method returns. It must accept the asyncResult parameter returned from the xtd::net::sockets::socket::begin_accept method.
Within the callback method, call the xtd::iasync_result::async_state method of the asyncResult parameter to obtain the xtd::net::sockets::socket::socket on which the connection attempt is being made. After obtaining the xtd::net::sockets::socket::socket, you can call the xtd::net::sockets::socket::end_accept method to successfully complete the connection attempt.
The xtd::net::sockets::socket::end_accept method blocks until a connection is pending in the incoming connection queue. The xtd::net::sockets::socket::end_accept method accepts the incoming connection and returns a new xtd::net::sockets::socket::socket that can be used to send data to and receive data from the remote host.
Note
If you receive a xtd::net::sockets::socket_exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
Examples
socket_tcp_ip_v4_without_thread.cpp.