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

◆ begin_receive_message_from()

xtd::sptr< xtd::iasync_result > xtd::net::sockets::socket::begin_receive_message_from ( std::vector< xtd::byte > &  buffer,
size_t  offset,
size_t  size,
xtd::net::sockets::socket_flags  socket_flags,
xtd::net::end_point remote_end_point,
xtd::async_callback  callback,
const std::any &  state 
)

Begins to asynchronously receive the specified number of bytes of data into the specified location of the data buffer, using the specified xtd::net::sockets::socket_flags, and stores the endpoint and packet information.

Parameters
bufferAn array of type xtd::byte that is the storage location for the received data.
offsetThe zero-based position in the buffer parameter at which to store the data.
sizeThe number of bytes to receive.
socket_flagsA bitwise combination of the xtd::net::sockets::socket_flags values.
remote_end_pointAn xtd::net::end_point that represents the source of the data.
callbackThe xtd::async_callback delegate.
stateAn object that contains state information for this request.
Returns
An xtd::iasync_result that references the asynchronous connection.
Exceptions
xtd::argument_out_of_range_exceptionsize is less than 0 or exceeds the size of the buffer.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
The asynchronous receive operation must be completed by calling the xtd::net::sockets::socket::end_receive_message_from method. Typically, the method is invoked by the callback delegate.
This method does not block until the operation completes. To block until the operation completes, use the xtd::net::sockets::socket::receive_message_from method.
To cancel a pending xtd::net::sockets::socket::begin_receive_message_from, call the xtd::net::sockets::socket::socket::close method.
This method reads data into the buffer parameter, and captures the remote host endpoint from which the data is sent, as well as information about the received packet. For information on how to retrieve this endpoint, refer to xtd::net::sockets::socket::end_receive_from. This method is most useful if you intend to asynchronously receive connectionless datagrams from an unknown host or multiple hosts.
Note
If you receive a xtd::net::sockets::socket_exception 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.