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

◆ enable_broadcast() [2/2]

socket & xtd::net::sockets::socket::enable_broadcast ( bool  value)

Sets a bool value that specifies whether the xtd::net::sockets::socket can send or receive broadcast packets.

Parameters
valuetrue if the xtd::net::sockets::socket allows broadcast packets; otherwise, false. The default is false.
Returns
This current instance.
Exceptions
xtd::net::sockets::socket_exceptionThis option is valid for a datagram socket only.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
Broadcasting is limited to a specific subnet, and must use User Datagram Protocol (UDP.) For Internet Protocol version 4, you can broadcast to your local subnet by sending a packet to 255.255.255.255; or you can use the directed broadcast address, which is the network portion of an Internet Protocol (IP) address with all bits set in the host portion. For example, if your IP address is 192.168.1.40 (a Class C address, with a netmask of 255.255.255.0 – the network portion is the first three octets, and the host portion is the last octet), your directed broadcast address is 192.168.1.255.
Setting this property on a Transmission Control Protocol (TCP) socket will have no effect.
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.