I am trying to receive UDP data that is broadcast to network address 192.168.103.255 port 3000 by PlayCap (http://www.signal11.us/oss/playcap/). I\'m having problems binding to
You don't bind to the broadcast address to receive broadcast packets. Just bind to the port and the address INADDR_ANY
(sorry, not sure how to express that in Java) and you will get packets to that port on the broadcast address.
It appears that the Datagram constructor takes the port number to bind to. Hope that helped...
Try this for your Java code instead:
public static void main(String[] args) {
try {
DatagramSocket s = new DatagramSocket(null);
InetSocketAddress address = new InetSocketAddress("192.168.103.255", 3000);
s.bind(address);
} catch (Exception e) {
e.printStackTrace();
}
}
Calling the no-arg constructor for a datagram socket will cause it to bind to a random, available port. Once bound, further attempts to (re)bind will throw a socket exception (with the error you were seeing). To 'defer' binding, you instead create the datagram socket in an unbound state (by passing a null in the constructor), then calling bind
later on.