File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes UDP programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "UDP programming" Watch "UDP programming" New topic

UDP programming

dsfkj asdfv

Joined: Jan 10, 2006
Posts: 1

I have a UDP client server pair that are supposed to communicate with each other by sending messages back and forth 1000 times. However, in my current program, it only does this once and then it hangs. My question is how can I modify and so that they can synchronize their communication for 1000 iterations.

Thanks a lot.

Virag Saksena
Ranch Hand

Joined: Nov 27, 2005
Posts: 71
Remember UDP is a stateless protocol, so if a packet is lost, it is lost.
You are assuming that the receive in the complementary program starts before the send in the other program.
If that does not happen then your packet is lost and your program hangs.

So after your send (whether sending the data or ack) you need to timeout after a certain time and then retry. And the timeouts in both the programs should be different based upon an initial shared key so both the programs do not time out at the same time.

<a href="" target="_blank" rel="nofollow">The Peak of Performance</a>
I agree. Here's the link:
subject: UDP programming
It's not a secret anymore!