0

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

try
{
  while(true)
   {
    socket.send(data);
   }
}catch (SocketTimeoutException e)
{
 // resend for which it occured
}

IS this possible to do ??

Nicolas Buduroi
  • 3,565
  • 1
  • 28
  • 29

2 Answers2

3

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!

Community
  • 1
  • 1
Nicolas Buduroi
  • 3,565
  • 1
  • 28
  • 29
2

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

nos
  • 223,662
  • 58
  • 417
  • 506
  • Hey I am programming for acks and thus would like to know... Its totally for my learning purposes –  Feb 13 '11 at 16:15
  • 1
    @user506710, Since you are programming the ack, you also need to program the timeout. Basically with UDP you have to many of the things TCP does for you, yourself (which is why many people end up using TCP) – Peter Lawrey Feb 13 '11 at 18:31