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

◆ send() [1/3]

size_t xtd::net::sockets::udp_client::send ( const std::vector< xtd::byte > &  dgram,
size_t  bytes,
const xtd::string hostname,
uint16  port 
)

xtd::net::sockets::udp_client::sends a UDP datagram to a specified port on a specified remote host.

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.
hostnameThe name of the remote host to which you intend to send the datagram.
portThe remote port number with which you intend to communicate.
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 values specified by the hostname and port parameters and returns the number of bytes successfully sent. You can send datagrams to the default broadcast address by specifying "255.255.255.255" for the hostname parameter value.
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.
Note
Do not provide a host name or port number 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.
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.