views:

67

answers:

2

I want to create a thread that listens for packets for a given time period (say 30 seconds) and then returns any messages that are received whilst listening. I can do the packet collection stuff, but what is the code pattern for the threading / blocking code that lets the asynch activity run for some set time period?

thanks

A: 

It depends on the code you are using to listen for packets, but basically (in pseudocode):

while(remainingTime > 0) {
   packet = listenForPackets(remainingTime);
   remainingTime = (initialTime + 30) - currentTime;
}
gustavogb
where does the threading logic go? waiting for a time period is trivial - as this example shows - what I dont know is what threading pattern/relationships I need...
MalcomTucker