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

◆ end_connect()

void xtd::net::sockets::socket::end_connect ( xtd::sptr< xtd::iasync_result async_result)

Ends a pending asynchronous connection request.

Parameters
async_resultAn xtd::iasync_result that stores state information for this asynchronous operation as well as any user defined data.
Exceptions
argument_exceptionasyncResult was not returned by a call to the xtd::net::sockets::socket::begin_connect method.
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_connect is a blocking method that completes the asynchronous remote host connection request started in the xtd::net::sockets::socket::begin_connect method.
Before calling xtd::net::sockets::socket::begin_connect, 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 xtd::net::sockets::socket::begin_connect returns. The callback method must accept the xtd::iasync_result returned by the xtd::net::sockets::socket::begin_connect method as a parameter.
Within the callback method, call the xtd::iasync_result::async_state method of the xtd::iasync_result 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_connect method to successfully complete the connection attempt.
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.