[
https://jira.jboss.org/jira/browse/JGRP-777?page=com.atlassian.jira.plugi...
]
Randy Watler commented on JGRP-777:
-----------------------------------
We have verified that this approach works to prevent channel crosstalk on Linux/Java 1.6
using jgroups 2.6.1.
Our particular test case involved a single process acting as a gateway between two
clusters using different mcast_addr and bind_addr settings on the same port. In the 2.6.1
code base, the 'group' setting used above in the MulticastSocket constructor above
is the mcast_addr setting, (or the mcast_addr_name member).
We would like to see this fix in 2.6.2 if there is going to be such a release.
Revisit multicast socket creation code
--------------------------------------
Key: JGRP-777
URL:
https://jira.jboss.org/jira/browse/JGRP-777
Project: JGroups
Issue Type: Task
Reporter: Bela Ban
Assignee: Bela Ban
Fix For: 2.7
[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 {
socket = new MulticastSocket(new InetSocketAddress(group,
port));
} 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 {
socket = new MulticastSocket(new
InetSocketAddress(port));
} 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 {
socket.close();
} catch(Exception c){
log.warn("Ignore exception while closing bad
multicast socket: " + c);
}
throw new RuntimeException(ad,e1);
}
return socket;
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira