14 Replies Latest reply on Jul 17, 2006 1:15 AM by tom.elrod

    binding multicast detector

    mazz

      This is probably a silly question but I can't explain this.

      I register and start a multicast detector - both its Address and DefaultIP are set to 127.0.0.1 (I also used 192.168.0.5 which is another of my IPs with same results) and I used port 16162.

      But when I look at netstat, it says its bound to "0.0.0.0":

      UDP 0.0.0.0:16162 *:*


      I would think it should tell me that its bound to 127.0.0.1:16162 no? I can confirm detector.getAddress() returns what I expect - 127.0.0.1 (I even made sure getDefaultIP is the same just to make sure).

      Anyone know why the multicast detector is showing up as binding to 0.0.0.0 and not the one I configured the detector for?

        • 1. Re: binding multicast detector

          I am little confused as to exactly which variables are getting set here. The Address and DefaultIP should be multicast IPs (224.x.x.x). Would actually expect an exception to be thrown if are set to 127.0.0.1 (e.g. java.net.SocketException: Not a multicast address).

          You can set the BindAddress to 127.0.0.1, but this is just basically to indicate which network interface to use.

          • 2. Re: binding multicast detector
            mazz

            Sorry, I misspoke. I was thinking one thing and said another.

            I meant to say both Address and DefaultIP are set the same (224.16.16.16).

            The BIND address is the thing I set to 127.0.0.1 (I also tried 192.168.0.5).

            Multicast Detector address: /224.16.16.16
            Multicast Detector port: 16162
            Multicast Detector bind address: /192.168.0.5
            Multicast Detector default IP: 224.16.16.16
            Multicast Detector default time delay: 5000
            Multicast Detector heartbeat time delay: 1000
            


            With this setup, "netstat" is showing the bind address to be 0.0.0.0 - below are some snippets of my netstat output - you can see 16162 has a local address of 0.0.0.0:

            C:\Documents and Settings\mazz>netstat -a -n -p U
            
            Active Connections
            
             Proto Local Address Foreign Address
             UDP 0.0.0.0:445 *:*
            ... UDP 0.0.0.0:16162 *:*...
             UDP 0.0.0.0:54925 *:*
            ...
             UDP 127.0.0.1:123 *:*
             UDP 127.0.0.1:1096 *:*
            ...
             UDP 192.168.0.3:123 *:*
             UDP 192.168.0.3:137 *:*
             UDP 192.168.0.3:138 *:*
             UDP 192.168.0.3:1900 *:*
             UDP 192.168.0.5:123 *:*
             UDP 192.168.0.5:137 *:*
            ...
            


            • 3. Re: binding multicast detector

              Short answer is I don't know why is showing 0.0.0.0. I tried it on my machine and get:

              java.exe:5456 UDP GINGER:16162 *:*

              You on windows or linux (my test was on windows)?

              • 4. Re: binding multicast detector
                mazz

                I'm on windows... show the numeric IP:

                netstat -n -a

                (note the -n) and see what you get.

                • 5. Re: binding multicast detector
                  mazz

                  Mine "looks" OK if I don't ask to see the actual IP:

                  UDP mazzlap:16162

                  But if I ask to see the actual IP, I see the 0.0.0.0.

                  • 6. Re: binding multicast detector

                    Mine showing the 0.0.0.0 as well with -n.

                    The bind address set it used to set the MulticastSocket's interface (http://java.sun.com/j2se/1.4.2/docs/api/java/net/MulticastSocket.html#setInterface(java.net.InetAddress)).

                    No idea why netstat showing 0.0.0.0 other than being part of the jdk implementation for previous method.

                    • 7. Re: binding multicast detector
                      mazz

                      Hmmm... I read the Javadocs and I still get confused - Interface vs. NetworkInterface, blah blah.

                      I'll keep an eye on this for any potential problems - it just doesn't seem right that netstat is showing that I'm bound to 0.0.0.0 (which I assume means all of them).

                      I guess no one else has ran into problems with this, so I'll take that as a good sign. Soldiering on...

                      • 8. Re: binding multicast detector

                        I tried with setting the NetworkInterface and am seeing the same thing.

                        • 9. Re: binding multicast detector
                          mazz

                          Maybe Bela or someone on his team can shed some light on this - why its happening and the meaning of those API methods (Interface vs. NetworkInterface).

                          • 10. Re: binding multicast detector
                            belaban

                            Did you use MulticastSocket.setNetworkInterface()/setInterface() ? Can you post some *short* sample code ?
                            Note I'm not subscribed to this forum, so you need to send me the code directly

                            • 11. Re: binding multicast detector

                              Here is a small test class showing the behavior.

                              public class MulticastSocketTest
                              {
                               public static void main(String[] args)
                               {
                               try
                               {
                               int port = Integer.parseInt(args[0]);
                               InetAddress interfaceAddress = InetAddress.getByName(args[1]);
                               NetworkInterface networkInterface = NetworkInterface.getByInetAddress(interfaceAddress);
                               InetAddress multicastAddress = InetAddress.getByName(args[2]);
                               System.out.println("port = " + port + "\ninterface address = " + interfaceAddress +
                               "\nnetwork interface = " + networkInterface + "\nmulticast address = " + multicastAddress);
                               MulticastSocket socket = new MulticastSocket(port);
                               socket.setInterface(interfaceAddress);
                               socket.setNetworkInterface(networkInterface);
                               socket.joinGroup(multicastAddress);
                              
                               Thread.currentThread().sleep(60000);
                               }
                               catch (Exception e)
                               {
                               e.printStackTrace();
                               }
                               }
                              }
                              


                              When I run this and pass the following arguments:

                              4900 192.168.1.100 224.1.9.1

                              I see the following doing 'netstat -n -a':

                              UDP 0.0.0.0:4900 *:*



                              • 12. Re: binding multicast detector
                                belaban

                                Okay, the following code below works:
                                package org.jgroups.tests;

                                import java.net.*;

                                /**
                                * @author Bela Ban
                                * @version $Id$
                                */
                                public class bla
                                {
                                public static void main(String[] args)
                                {
                                try
                                {
                                int port = Integer.parseInt(args[0]);
                                InetAddress interfaceAddress = InetAddress.getByName(args[1]);
                                NetworkInterface networkInterface = NetworkInterface.getByInetAddress(interfaceAddress);
                                InetAddress multicastAddress = InetAddress.getByName(args[2]);
                                System.out.println("port = " + port + "\ninterface address = " + interfaceAddress +
                                "\nnetwork interface = " + networkInterface + "\nmulticast address = " + multicastAddress);
                                SocketAddress saddr;
                                saddr=new InetSocketAddress(interfaceAddress, port);
                                MulticastSocket socket = new MulticastSocket(saddr);
                                socket.setInterface(interfaceAddress);
                                socket.setNetworkInterface(networkInterface);
                                socket.joinGroup(multicastAddress);

                                Thread.sleep(600000);
                                }
                                catch (Exception e)
                                {
                                e.printStackTrace();
                                }
                                }
                                }

                                • 13. Re: binding multicast detector
                                  mazz

                                  That's weird.. so you have to pass the interface address (InetSocketAddress object) to the constructor for it to work, even though you call the setter (setInterface) with the same address?

                                  Sounds like a JDK bug to me :-)

                                  • 14. Re: binding multicast detector