Android Question UDP packet timeout

dualznz

Member
Licensed User
Longtime User
Hi all
i have a question is there any way that when requesting a packet via UDP that if there is no response in say 2000 milliseconds it will carry on to the next packet in the for next loop.

and it could just respond with a message box informing that there was no success in the packet?

i can gather data fine within the packets but if the server end goes offline this method would be used to stop the program from becoming unresponsive.

cheers
 
Last edited:

JordiCP

Expert
Licensed User
Longtime User
In UDP there is no handshaking mecanism, so there is no automatic way to know if your message has been received.

If you want to use UDP and keep track of the "connection" state, the other side must send some packet from time to time (some kind of keepalive signal) or also, respond to some of the packets you send according to some predefined protocol

Otherwise, it's better to use TCP
 
Upvote 0

merlin2049er

Well-Known Member
Licensed User
Longtime User
It's easy to implement a time out feature. Just setup a timer for 200 ms, enable it when you send your packet, then on your first timer tick disable the timer and check the udp response.
If it's empty, you've timed out, or if you know the response you can match it and do something...
 
Upvote 0
Top