Unlike synchronous Accept , BeginAccept does not provide a socket for a newly created connection. EndAccept however, but it also stops future connections from accepting; so I came up with the following code to allow several "clients" to connect to my server:
serverSocket.BeginAccept(AcceptCallback, serverSocket);
AcceptCallback code:
void AcceptCallback(IAsyncResult result) { Socket server = (Socket)result.AsyncState; Socket client = server.EndAccept(result);
Is there a better way to do this? This seems to be a little โhacked," because it essentially repeats asynchronous calls cyclically.
Perhaps there is overhead associated with multiple async method calls, such as creating multiple threads?
source share