Name: boT120536 Date: 03/20/2001
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Classic VM (build 1.3.0, green threads, nojit)
Imagine that you have the following class running on host a:, which is
multi-homed:
-----------------------
import java.net.*;
import java.util.*;
import java.io.*;
class bcc
{
static String getString(DatagramPacket dp)
throws Exception
{
return new String(dp.getData(),0,dp.getLength(),"US-ASCII");
};
public static void main(String[] args)
throws Exception
{
new bcc().run(args);
};
public void run (String[] args)
throws Exception
{
DatagramSocket socket = new DatagramSocket();
InetAddress addr = InetAddress.getByName("255.255.255.255");
socket.setSoTimeout(500);
int count = 0;
DatagramPacket send = new DatagramPacket( new byte[0], 0, addr, 33626 );
DatagramPacket recv = new DatagramPacket( new byte[512], 512 );
while ( true ) {
byte[] bytes = "ThisIsATest".getBytes("US-ASCII");
send.setData(bytes);
send.setLength(bytes.length);
System.out.println("sending: "+getString(send));
socket.send(send);
System.out.println("receive");
try {
recv.setData(new byte[512]);
recv.setLength(512);
socket.receive(recv);
System.out.println("source: "+recv.getAddress());
System.out.println("length: "+recv.getLength());
System.out.println(getString(recv));
System.out.println();
System.out.println();
} catch ( InterruptedIOException i ) {
System.out.println("timeout");
};
System.out.println("waiting");
synchronized(this) {
wait(500);
};
};
};
};
----------------------
Imagine further, that you have a UDP 'echo' program running on one of the
networks attached to this host. If my understanding of the spec is correct,
this echo program should receive broadcasts regardless of *WHICH* interface's
network it is attached to. In my experience, however, this is not the case.
On a machine where 'InetAddress.getLocalAddress()' reports '92.xxx.xxx.xxx',
but which also has an interface on '10.xxx.xxx.xxx', addresses sent to the
limited broadcast address do NOT get received by other hosts on the 10.x
network. If I send them instead to 10.255.255.255, they are received by
these hosts. Since I have no other hosts on the 92.x address, I can only
make an educated guess that these packets are going to that 'front door' addr,
instead of trying all 'doors'.
(Review ID: 119015)
======================================================================
- duplicates
-
JDK-4327220 java.net.* does not provide support for multihomed hosts
-
- Resolved
-