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

◆ accept()

socket xtd::net::sockets::socket::accept ( )

Creates a new xtd::net::sockets::socket for a newly created connection.

Returns
A xtd::net::sockets::socket for a newly created connection.
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.
xtd::invalid_operation_exceptionThe accepting socket is not listening for connections. You must call xtd::net::sockets::socket::bind and xtd::net::sockets::socket::listen before calling xtd::net::sockets::socket::accept().
Remarks
xtd::net::sockets::socket::accept synchronously extracts the first pending connection request from the connection request queue of the listening socket, and then creates and returns a new xtd::net::sockets::socket. You cannot use this returned xtd::net::sockets::socket to accept any additional connections from the connection queue. However, you can call the xtd::net::sockets::socket::remote_end_point method of the returned xtd::net::sockets::socket to identify the remote host's network address and port number.
In blocking mode, xtd::net::sockets::socket::accept blocks until an incoming connection attempt is queued. Once a connection is accepted, the original xtd::net::sockets::socket continues queuing incoming connection requests until you close it.
If you call this method using a non-blocking xtd::net::sockets::socket, and no connection requests are queued, xtd::net::sockets::socket::accept throws a xtd::net::sockets::socket_exception. 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.
Note
Before calling the xtd::net::sockets::socket::accept method, you must first call the xtd::net::sockets::socket::listen method to listen for and queue incoming connection requests.
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.