Hi
I'm writing some network program and made something that look like server. The problem is that I can not shut it down. The code looks like this:
CNetwork
{
void Start ()
{
<socket creation, binding, etc.....>
mSocket.BeginAccept(new AsyncCallback(AcceptConn),mSocket);
<code continue.......>
}
void Stop ()
{
if (mSocket.Connected)
mSocket.Shutdown (SocketShutdown.Both);
mSocket.Close();
mSocket = null;
<code continue......>
}
<code continue......>
}
Error ocures when: CNetowrk.Start() and immideatly CNetowrk.Stop(). It seems like when I creating socket and immideatly starting with BeginAccept I can not end this -> I just can't do socket.Close() and socket = null. The error:
System.InvalidOperationException with additional information: AcceptCallback
is thrown. Is there any way to end BeginAccept operation and shutdown the socket

Best way to shutdown async socket
programmer01
Socket is in process of accepting some cleint, try to call EndAccept() before you call other functions to close the socket.
I hope this will work.
Best Regards,