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

◆ receive()

std::vector< xtd::byte > xtd::net::sockets::udp_client::receive ( xtd::net::ip_end_point remote_end_point)

Returns a UDP datagram that was sent by a remote host.

Parameters
remote_end_pointAn xtd::net::ip_end_point that represents the remote host from which the data was sent.
Returns
An array of type Byte that contains datagram data.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the underlying socket.
xtd::object_closed_exceptionThe underlying xtd::net::sockets::socket has been closed.
Remarks
The xtd::net::sockets::udp_client::receive method will block until a datagram arrives from a remote host. When data is available, the xtd::net::sockets::udp_client::receive method will read the first enqueued datagram and return the data portion as a byte array. This method populates the remoteEP parameter with the xtd::net::ip_address and port number of the sender.
If you specify a default remote host in the xtd::net::sockets::udp_client::connect method, the xtd::net::sockets::udp_client::receive method will accept datagrams from that host only. All other datagrams will be discarded.
If you receive a xtd::net::sockets::socket_exception, use xtd::net::sockets::socket_exception.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
Note
If you intend to receive multicasted datagrams, do not call the xtd::net::sockets::udp_client::connect method prior to calling the xtd::net::sockets::udp_client::receive method. The xtd::net::sockets::udp_client you use to receive datagrams must be created using the multicast port number.
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.