[jboss-jira] [JBoss JIRA] Reopened: (JGRP-777) Revisit multicast socket creation code
Bela Ban (JIRA)
jira-events at lists.jboss.org
Thu Sep 18 11:52:21 EDT 2008
[ https://jira.jboss.org/jira/browse/JGRP-777?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Bela Ban reopened JGRP-777:
---------------------------
need to backport this to 2.6.5
> 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.6.5, 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
More information about the jboss-jira
mailing list