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

◆ exclusive_address_use() [2/2]

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

Gets a boolean value that specifies whether the xtd::net::sockets::socket allows only one process to bind to a port.

Parameters
valuetrue if the xtd::net::sockets::socket allows only one socket to bind to a specific port; otherwise, false. The default is true for Windows Server 2003 and Windows XP Service Pack 2, and false for all other versions.
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.
xtd::invalid_operation_exceptionxtd::net::sockets::socket::bind has been called for this xtd::net::sockets::socket.
Remarks
If xtd::net::sockets::socket::exclusive_address_use is false, multiple sockets can use the xtd::net::sockets::socket::bind method to bind to a specific port; however only one of the sockets can perform operations on the network traffic sent to the port. If more than one socket attempts to use the xtd::net::sockets::socket::bind method to bind to a particular port, then the one with the more specific IP address will handle the network traffic sent to that port.
If xtd::net::sockets::socket::exclusive_address_use is true, the first use of the xtd::net::sockets::socket::bind method to attempt to bind to a particular port, regardless of Internet Protocol (IP) address, will succeed; all subsequent uses of the xtd::net::sockets::socket::bind method to attempt to bind to that port will fail until the original bound socket is destroyed.
This property must be set before xtd::net::sockets::socket::bind is called; otherwise an xtd::invalid_operation_exception will be thrown.
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.