Re: CAsyncsocket derived class being run as a thread
- From: Ian Semmel <isemmelNOJUNK@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 08 Jan 2006 05:04:34 +1000
You don't have to use AfxBeginThread to start your thread
You can do something like
UDPListener* pThread = new UDPListener ();
pThread->SetReceivePort( iPort);
pThread -> CreateThread (); // this could go in your Start() function
paul@xxxxxxxxxxx wrote:
Hi Joe and Scott, Thanks for your replies - it will give me something to digest over the weekend. A pity the kind souls at work haven't given me long enough to actuall do any learning on the subject or testing. Sigh.
I did ask a rudimentary question about threading but its disappeared from my news feed, so it must have vanished. Anyway, what I asked was this:
If I do something like pThread = AfxBeginClass (RUNTIME_CLASS (UDPListener)); // UDPListener is derived from CWinThread
Can I access the member functions like this: (UDPListener *) pThread->SetReceivePort( iPort); // set the listening port pThread->Start(); // start the thread going
If not, how can I access the thread functions?
Also, as you mention above, yes, I am using OnReceive(...) to receive messages from the specified port. If I start a thread going, as discussed above, will the UDP packets still be received? A friend at work has written something in C# and suggested a while(true){ .... } loop, with a call to UdpClient.Receive(...) placed in the middle of it to pick up packets, but it just seems more natural (to me anyway!) to let OnReceive(...) do everything rather than explicitly informing your packet listener to do it in a loop.
.
- Follow-Ups:
- Re: CAsyncsocket derived class being run as a thread
- From: Paul Lee
- Re: CAsyncsocket derived class being run as a thread
- References:
- CAsyncsocket derived class being run as a thread
- From: paul
- Re: CAsyncsocket derived class being run as a thread
- From: Joseph M . Newcomer
- Re: CAsyncsocket derived class being run as a thread
- From: paul
- Re: CAsyncsocket derived class being run as a thread
- From: Joseph M . Newcomer
- Re: CAsyncsocket derived class being run as a thread
- From: paul
- CAsyncsocket derived class being run as a thread
- Prev by Date: Re: CFormView & refresh problems
- Next by Date: Re: question on the "spin" control
- Previous by thread: Re: CAsyncsocket derived class being run as a thread
- Next by thread: Re: CAsyncsocket derived class being run as a thread
- Index(es):
Relevant Pages
|