Creates a new Socket instance to handle an incoming connection.
[Visual Basic] Public Function Accept() As Socket [C#] public Socket Accept(); [C++] public: Socket* Accept(); [JScript] public function Accept() : Socket;
If there is a pending connection request, a Socket instance to handle the incoming connection. If there is no pending connection for an asynchronous socket, a null reference (in Visual Basic Nothing).
Exception Type | Condition |
---|---|
InvalidOperationException | The Accept call is made on a synchronous socket with no pending connection requests. |
The Accept method extracts the first connection request on the queue of pending requests and creates a new Socket instance to handle the request. The Socket returned by Accept is a duplicate of the current Socket.If Accept is called on an asynchronous socket with no pending connection requests, null will be returned.
The following code will display any error message returned by Accept.
[C#]
result = aSocket.Accept if (result <> 0) { Console.WriteLine("Winsock error: " + Convert.ToString(Marshal.GetLastWin32Error()) ); }
Socket Class | Socket Members | System.Net.Sockets Namespace