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

◆ disconnect()

void xtd::net::sockets::socket::disconnect ( bool  reuse_socket)

Closes the socket connection and allows reuse of the socket.

Parameters
reuse_sockettrue if this socket can be reused after the current connection is closed; otherwise, false.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
xtd::object_closed_exceptionThe xtd::net::sockets::socket has been closed.
Remarks
If you are using a connection-oriented protocol, you can use this method to close the socket. This method ends the connection and sets the xtd::net::sockets::socket::connected property to false. However, if reuseSocket is true, you can reuse the socket.
To ensure that all data is sent and received before the socket is closed, you should call xtd::net::sockets::socket::shutdown before calling the xtd::net::sockets::socket::disconnect method.
If you need to call xtd::net::sockets::socket::disconnect without first calling xtd::net::sockets::socket::shutdown, you can set the xtd::net::sockets::socket::dont_linger_socket option to false and specify a nonzero time-out interval to ensure that data queued for outgoing transmission is sent. xtd::net::sockets::socket::disconnect then blocks until the data is sent or until the specified time-out expires. If you set xtd::net::sockets::socket::dont_linger to false and specify a zero time-out interval, xtd::net::sockets::socket::close releases the connection and automatically discards outgoing queued data.
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.