setsotimeout in java

By : mare

I am trying to send data through DatagramSocket and would like to do this that if the data sent has exceeded the timeout of its acknowledgement then it should be resend.

Can we use the option of DatagramSocket.SetSoTimeout for it ?? If yes how can I ??

For eg

}catch (SocketTimeoutException e)
 // resend for which it occured

IS this possible to do ??

By : mare


UDP is unreliable, it has no ack's. i.e. There's no acknowledgement timer that can be exceeded.

By : nos

The documentation seems rather clear about setSoTimeout purpose:

a call to receive() for this DatagramSocket will block for only this amount of time

First it doesn't have anything to do with send and second it only timeout if it's blocking for a certain amount of time.

If you want reliability use TCP. If you absolutely need/want to use UDP you'll have to devise your own reliability mechanism. Here's another SO question about this particular problem:

What do you use when you need reliable UDP?

Basically it really depend on what you're doing, because if you need a generic solution, you'll end up reinventing TCP!

This video can help you solving your question :)
By: admin