How do you send and receive UDP packets in Java on a multihomed machine?
Question
I have a machine with VmWare installed which added two extra network interfaces. The OS is Vista. I have two Java applications, one which broadcasts datagrams, and one which receives those datagrams. The problem I'm having is that unless I disable both VmWare network interfaces, the receiver can't receive the datagrams.
What is the best way to make that work without disabling the interfaces?
Solution
Look at the alternate constructor for DatagramSocket:
DatagramSocket(int port, InetAddress laddr)
Creates a datagram socket, bound to the specified local address.
I'm guessing you're only specifying the port.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow