[Dieter Cailliau]
I looked into the UDP class (trunk) and found out that the MulticastSocket(port) constructor is used.
This doesn't work well on many linux systems: http://forum.java.sun.com/thread.jspa?threadID=5216130&messageID=9875372 It's not entirely clear who's 'fault' this is, but i have a workaround below.
I experienced this problem in jgroups when i tried to set up 2 distinct processes on the same machine, that use a different stack with different UDP mcast_addr. Still the one process would complain about the other: discard msg from different group.
java 1.5.0_10-b03, jgroups 2.5.0.GA.
The code i use for making MulticastSockets is below. In combination with a default gateway and preferIPv4 this was the only way to make sure that my socket only received datagrams for the group it actually joined. Using the constructor with only a port results in a sokcet receiving ALL datagrams that are multicasted to that port (regardless of the group address it joined!).
Can someone please give some feedback on this, and consider if this is a fix for UDP?
public static MulticastSocket createMulticastSocket(int TIMEOUT_MS, InetAddress group, int port) {
MulticastSocket socket = null;
try
catch (BindException e1) {
String warn = null == System.getProperty("java.net.preferIPv4Stack") ? "-Djava.net.preferIPv4Stack != true ??" : "java.net.preferIPv4Stack=true";
log.warn("Unable to create the multicast socket at address " + group + ":" + port + "; I'll fall back to the windows solution (create the socket with port only) " + warn,e1);
// Windows fallback
try
catch (IOException e)
{ throw new RuntimeException(e1); }} catch (Exception e1)
{ throw new RuntimeException(e1); }try
{ socket.setSoTimeout(TIMEOUT_MS); socket.joinGroup(group); } catch (Exception e1) {
byte[] address = group.getAddress();
String ad = address[0] + "." + address[1] + "." + address[2] + "." + address[3] + ":" + port + " " + e1.toString();
try
catch(Exception c)
{ log.warn("Ignore exception while closing bad multicast socket: " + c); } throw new RuntimeException(ad,e1);
}
return socket;
}
- is incorporated by
-
JBPAPP-1539 Elminate Multicast Cross Talk Problem (Collocated Instances Must Use Different Ports Regardless of Multicast Address)
- Resolved
- is related to
-
JGRP-639 UDP: bind MulticastSocket to multicast address
- Closed