41143

UDP response not reaching back client

Question:

I am working on a application which sends UDP packet to initiate a Processing and needs to send back response on same socket after 3-5 minutes, but issue is that when response is sent back, it never reaches client. I am using java. Any suggestions, how we can keep the socket alive over longer period of time?

--

Answer1:

<blockquote>

Any suggestions, how we can keep the socket alive over longer period of time?

</blockquote>

and

<blockquote>

Is there a way to set UDP timeout setting ...?

</blockquote>

UDP is connectionless. If an application binds to a UDP server-socket and listens, it can wait for messages to arrive indefinitely.

The flipside is that there is no way to detect a lost UDP message at the protocol / socket level. If one machine sends a UDP message to another one, the first machine has no direct way of knowing if the message has arrived or not? There are no transport level timeouts to tell the sender to retransmit.

If you need reliability, timeouts, automatic retransmission, etc, you are better of using a connection-based transport protocol such as TCP.

<blockquote>

Issue as suggested by a colleague, might be that firewall closes UDP connections if there is no activity for certain period of time, for communication to be reliable one need to implement timeout probe.

</blockquote>

On the face of it, that explanation is nonsensical. UDP is connectionless, so there is no connection to close, or to keep alive.

The real explanation is likely to be one of the following:

<ul><li>

The UDP requests or the UDP replies are being blocked by firewall software on one or other of the machines, or somewhere in the network.

</li> <li>

Something is not right about the way that the messages are being sent or received.

</li> <li>

You are trying to send UDP messages through a NAT gateway; e.g. to a machine whose IP address cannot be routed from the other. Special measures such as <a href="http://en.wikipedia.org/wiki/UDP_hole_punching" rel="nofollow">UDP hole punching</a> are required to get UDP traffic to a NATed host, and it may be necessary to send keep-alive packets to keep a "UDP hole" from timing out.

</li> </ul>

If you are trying to send UDP through a NAT firewall from Java, there are various (3rd-party) Java libraries for doing this. Search for "stun" and "turn" or "ice" together with "java" and "udp", or read the following for a started:

<ul><li><a href="https://stackoverflow.com/questions/2039147/stun-turn-ice-library-for-java" rel="nofollow">STUN, TURN, ICE library for Java</a></li> </ul>

These solutions all require you to take steps to "refresh" the NAT bindings to keep the firewall "hole" open.

Recommend

  • Get multiple keys from json in Python
  • JSON object being returned should be array
  • Convert a flat datastructure into a tree
  • ie save onunload bug
  • JQuery insert cell to specific position of tr value and td value
  • Good interpolation method for color mixing?
  • How to retrieve Text type from Datastore Google Cloud?
  • DCG and left recursion
  • Confusing behaviour when invoking async methods inside ASP.NET
  • Cassandra CQL paging for Composite key
  • How can we trace push notifications being sent to the Apple APNS server from IBM MobileFirst 7.0?
  • Override a private method in the lib folder of a gem
  • java add items to arraylist at random time intervals
  • WPF - MVVM Screen Management
  • Can i detect if a user canceled navigation from Google Maps App
  • How to query property value when property name is a parameter?
  • Get MP3 ID3 meta data and song duration using AudioStreamer
  • PHP problems with current url
  • AWS Cognito- get user information with ID
  • Keep Sql Connection open for iterating many requests? Or close each step?
  • PHP: Get HTTP Protocol Version (HTTP/1.1 vs HTTP/2)
  • UIImagePickerControllerDelegate Methods Not Called When Delegate Not UIViewController
  • Base64 as method of sanitizing user input for Mysql
  • Vigenere cipher not working
  • How can we prepend rows to a react native list-view?
  • Can I use AllJoyn Framework for Wifi Direct in iOS?
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • Firefox Extension - Monitor refresh and change of tab
  • ADO and msqli connections very slow
  • NHibernate Validation Localization with S#arp Architecture
  • How can I send an e-mail from a vbs script
  • javaw.exe and eclipse startup problems
  • Accessing IRQ description array within a module and displaying action names
  • Can Jackson SerializationFeature be overridden per field or class?
  • Redux, normalised entities and lodash merge
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Android Studio and gradle
  • Getting Messege Twice Using IMvxMessenger
  • How to get NHibernate ISession to cache entity not retrieved by primary key