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

◆ send() [2/3]

size_t xtd::net::sockets::udp_client::send ( const std::vector< xtd::byte > &  dgram,
size_t  bytes,
const xtd::net::ip_end_point end_point 
)

xtd::net::sockets::udp_client::sends a UDP datagram to the host at the specified remote endpoint.

Parameters
dgramAn array of type Byte that specifies the UDP datagram that you intend to send, represented as an array of bytes.
bytesThe number of bytes in the datagram.
end_pointAn xtd::net::ip_end_point that represents the host and port to which to send the datagram.
Returns
The number of bytes sent.
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::send method sends datagrams to the specified endpoint and returns the number of bytes successfully sent. Before calling this overload, you must first create an xtd::net::ip_end_point using the IP address and port number of the remote host to which your datagrams will be delivered. You can send datagrams to the default broadcast address, 255.255.255.255, by specifying SocketOptionName.Broadcast for the Address property of the xtd::net::ip_end_point. After you have created this xtd::net::ip_end_point, pass it to the xtd::net::sockets::udp_client::send method as the endPoint parameter.
If you want to send datagrams to any other broadcast address, use the xtd::net::sockets::udp_client::client method to obtain the underlying xtd::net::sockets::socket, and set the socket option to SocketOptionName.Broadcast. You can also revert to using the xtd::net::sockets::socket class.
Do not provide an endPoint parameter to this method if you have already established a remote host with the xtd::net::sockets::udp_client::connect method. If you do, the xtd::net::sockets::udp_client::send method will throw a xtd::net::sockets::socket_exception. 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 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.