How to Identify "if a UDP socket did not receive any packet in a certain time interval".


 The following line of code exists in my program
 where dp is a datagram packet, d is a datagram socket.

  Now, my program waits for a packet to arrive and then depending on what arrived the rest of the program depends., but what i want to do is if this socket does not receive any packet for a certain interval of time , say 5seconds, i want to perform some other task. The difficulty is how do i get out of this line of code, when i dont receive any packet for the predefined interval of time ( and understand that it came to the next line because of "not receiving any packet for 5 seconds"). It just simply does not come out of that line until it receives a datagram packet.

 Thanks and regards,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

set a timeout for the socket:


prashanth_gurijalaAuthor Commented:
ok, but when the timeout occurs, how will i find out that, it came out of that statement because of timeout.....
a SocketTimeoutException will be throw

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.