473,412 Members | 5,361 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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 2067
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Boltar | last post by:
Hello, I am trying to use a CustomValidator control to perform client-side validation via a server callback. I have an example below that validates if a textbox contains an odd number. I...
0
by: Robert | last post by:
After failing on a yield/iterator-continuation problem in Python (see below) I tried the Ruby (1.8.2) language first time on that construct: The example tries to convert a block callback interface...
3
by: ryan.mitchley | last post by:
Hi all I have a class (cPort) that is designed to receive objects and, depending on the type, call a handler (callback) in any descendant of a cProcessBlock class. Callback functions take a...
4
by: Jimmy | last post by:
I need to use Asynchronous Socket functions in a server application and am learning from sources such as the MSDN2 (http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx). What I observed is that...
0
by: Brian | last post by:
Hi, I've been trying to get a simple client / script callback to work. I was using IE6 to the ASP Development Server / IIS 5 and it just didn't work. I ended up using an example straight from an...
2
by: Cylix | last post by:
I have a tcpListen on a new thread in my application. When start the tcpListen, the process will hold in that line. I would like to terminate the tcpListen by abort the thread, but fail. How can...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.