Hi,
I am using an AsyncCallback to receive a TcpClient on incoming
connections. The code below works fine until I start the application and
no connection is received within the time limit.
I could easily try / catch the code causing the problem but I would like
to understand why this problem is happening.
I was unable to find any field on the TcpListener that would indicate
the Listenign socket was stopped.
http://pastebin.com/882324 or
static private TcpClient _connectedClien t;
static void AcceptClient(IA syncResult ar)
{
TcpListener server = (TcpListener)ar .AsyncState;
_connectedClien t = _listenSocket.E ndAcceptTcpClie nt(ar);
}
static void Main()
{
TcpListener _listenSocket = new TcpListener(800 5);
_listenSocket.S tart();
_listenSocket.B eginAcceptTcpCl ient(new AsyncCallback(A cceptClient),
_listenSocket);
//Wait for 5 seconds for a connection
Thread.Sleep(50 00);
if( _connectedClien t == null )
{
//Failed to get a connection
//This call to stop invokes a call to AcceptClient
//This cause AcceptClient to crash on the EndAcceptTcpCli ent
_listenSocket.S top();
}
else
{
//Application begins...
}
}
*** Sent via Developersdex http://www.developersdex.com ***