Bucky
Contributor
In writing code to handle the listening and connection-accepting
of a Socket instance, I've run into a snag after calling
BeginAccept. After calling BeginAccept, I want to be able to cancel
the calling of my callback function and essentially stop the Socket
from listening before it actually receives a connection request.
When a connection request does come, the Socket accepts it,
receives from it, and closes it fine, but I'd like to be able to stop
the Socket from listening before a connection is requested.
GavinO suggested a very creative kludge that invoves creating a
new Socket and connecting with listening one so that the
connection would be made (behind the scenes) and then
successfully closed right away. Needless to say, I'm hoping
there's a more elegant way.
Oh, and this is the code I'm using to start the accept callback:
Thanks.
of a Socket instance, I've run into a snag after calling
BeginAccept. After calling BeginAccept, I want to be able to cancel
the calling of my callback function and essentially stop the Socket
from listening before it actually receives a connection request.
When a connection request does come, the Socket accepts it,
receives from it, and closes it fine, but I'd like to be able to stop
the Socket from listening before a connection is requested.
GavinO suggested a very creative kludge that invoves creating a
new Socket and connecting with listening one so that the
connection would be made (behind the scenes) and then
successfully closed right away. Needless to say, I'm hoping
there's a more elegant way.
Oh, and this is the code I'm using to start the accept callback:
C#:
IAsyncResult beginAcceptResult;
beginAcceptResult = listenSocket.BeginAccept(new AsyncCallback(ListenCallback), null);
Thanks.