Link to home
Start Free TrialLog in
Avatar of prashanth_gurijala
prashanth_gurijala

asked on

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

Hai,

 The following line of code exists in my program
 d.receive(dp)
 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,
 PG.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

set a timeout for the socket:

d.setSoTimeout(5000);

Avatar of prashanth_gurijala
prashanth_gurijala

ASKER

ok, but when the timeout occurs, how will i find out that, it came out of that statement because of timeout.....
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial