Mono Class Library: System.Net.Sockets.Socket Overview | MembersSystem.Net.Sockets.Socket.BeginAccept Method |
Begins an asynchronous operation to accept an incoming connection request. [Edit]
|
- callback
- A AsyncCallback delegate, or null. [Edit]
- state
- An application-defined object, or null. [Edit]
A IAsyncResult instance that contains information about the asynchronous operation. [Edit]
Type Reason System.Net.Sockets.SocketException Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.[Edit]ObjectDisposedException The current instance has been disposed. [Edit]
To retrieve the results of the operation and release resources allocated by the Socket.BeginAccept(AsyncCallback, object) method, call the Socket.EndAccept(IAsyncResult) method, and specify the IAsyncResult object returned by this method.
Note: The Socket.EndAccept(IAsyncResult) method should be called exactly once for each call to the Socket.BeginAccept(AsyncCallback, object) method.If the callback parameter is not null, the method referenced by callback is invoked when the asynchronous operation completes. The IAsyncResult object returned by this method is passed as the argument to the method referenced by callback. The method referenced by callback can retrieve the results of the operation by calling the Socket.EndAccept(IAsyncResult) method.
The state parameter can be any object that the caller wishes to have available for the duration of the asynchronous operation. This object is available via the IAsyncResult.AsyncState property of the object returned by this method.
To determine the connection status, check the Socket.Connected property, or use either the Socket.Poll(int, SelectMode) or Socket.Select(IList, IList, IList, int) method.
Note:[Edit]For more information, see Socket.Accept, the synchronous version of this method.
The following excerpt from the System.Net.Sockets.Socket class overview example outlines an asynchronous accept operation.
C# Example public class Server { static void Main() { . . . listenSocket.BeginAccept( new AsyncCallback(Server.acceptCallback), listenSocket); . . . // EndAccept can be called here . . . } public static void acceptCallback(IAsyncResult asyncAccept) { Socket listenSocket = (Socket)asyncAccept.AsyncState; Socket serverSocket = listenSocket.EndAccept(asyncAccept); serverSocket.BeginReceive(...); . . . } }
Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0