Callback Example for TcpListen

G

Guest

Is there a callback example for TcpListen? I don't see a way to create a
trigger in .Net that would listen for socket requests and then trigger my
acceptConnection (thsClient) method. BTW .. I am checking pending so that I
can stop the thread and switch ports to listen to if needed. Otherwise, I'd
be happy to just use listen.Accept ... which blocks.

Presently I have:

bool bRun = true;
private void ListenThread ()
{
TcpListen listen = new TcpListen (localAddr, 5051);
listen.Start ();

while (bRun)
{
if (listen.Pending ())
{
TcpClient thsClient = listen.AcceptTcpClient ();

acceptConnection (thsClient);
}
}
listen.stop ();
}
 
N

Nicholas Paldino [.NET/C# MVP]

What you could do is wait on the thread, and then fire an event from the
thread when the call stops blocking. You can do this on a worker thread, so
that you don't have to worry about blocking a thread that is important to
you.

Hope this helps.
 
Top