UDP socket send blocking when no ARP responses
843790Dec 9 2008 — edited Dec 11 2008I am struggling with a java socket issue using UDP datagram socket.
When we send over 1024 bytes to an address whose machine is turned off (ie no ARP response), the java socket on client machine is hung up for 4 seconds on the send method while ARP query is made.
Sending 1024 or less bytes and there is no delay encountered....SetSoTimeout and setSendBuffer does not help either.
The question is if there is a setting in java sockets, the OS (windows), or the adapter that affects the ARP timeout for UDP datagram sockets that will avoid the blocking time on the send method.
I can reprocuce this 4 second delay with code below, and it only happens when I send over 1024 bytes in the datagram socket, on machine with the gigabit adapter.
Thanks.
Here is the code I use:
String dummy_ip = "10.86.129.224"; //make sure this machine is off, and you run this program on MCS 7845
int x = 1010;
do {
x = x + 2;
StringBuffer sb = new StringBuffer();
for (int i=0;i<x;i++) sb.append("F");
byte[] data = sb.toString().getBytes();
long start = System.currentTimeMillis();
DatagramSocket sendsocket2 = new DatagramSocket();
DatagramPacket p = new DatagramPacket(data, data.length, InetAddress.getByName(dummy_ip), 5060);
sendsocket2.send(p);
sendsocket2.close();
System.out.println("\n\n************* "+x+" bytes delay= " + (System.currentTimeMillis() - start));
} while (x < 1030);