Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you send and receive UDP packets in Java on a multihomed machine?

Tags:

java

sockets

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?

like image 373
Jay R. Avatar asked Sep 07 '08 18:09

Jay R.


1 Answers

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.

like image 119
Joe Liversedge Avatar answered Sep 22 '22 12:09

Joe Liversedge