471,605 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Callback Example for TcpListen

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 ();
}
Dec 22 '05 #1
1 2026
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ENetArch" <EN******@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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 ();
}

Dec 24 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Boltar | last post: by
3 posts views Thread by ryan.mitchley | last post: by
4 posts views Thread by Jimmy | last post: by
2 posts views Thread by Cylix | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.