Hi Trustin,<div><br></div><div>Thanks for the reply, below is the example that works, it&#39;s from internet, and mean-while I found out what it didn&#39;t like:</div><div><br></div><div>If instead:</div><div><span><div><div>
DatagramChannel datagramChannel = (DatagramChannel) bootstrap.bind(new InetSocketAddress(localIpAddress, multicastPort));</div></div><div><br></div><div>I do something like:</div><div><div>DatagramChannel datagramChannel = (DatagramChannel) bootstrap.bind(new InetSocketAddress(multicastPort));</div>
</div></span></div><div><br></div><div>It works.</div><div><br></div><div>I assume that it prefers binding to (lo) instead (eth0), I don&#39;t know if it&#39;s because of netty or due to system configuration.</div><div><br>
</div><div>Best regards,</div><div>Alex.</div><div><br></div><div>-------------------------------------------------------------------------------------------------------------------</div><div><div>import java.net.*;  /* import networking package */</div>
<div>import java.io.*;   /* import input/output package */</div><div><br></div><div>public class mcreceive {</div><div>public static final int MAX_LEN  = 1024;  /* max receive buffer */</div><div>public static final int MIN_PORT = 1024;  /* min network port */</div>
<div>public static final int MAX_PORT = 65535; /* max network port */</div><div><br></div><div>public static void main(String argv[]) {</div><div>        InetAddress mcAddress=null; /* multicast address */</div><div>        int mcPort=0;               /* multicast port */</div>
<div>        int ttl=1;                  /* time to live */</div><div>        boolean done=false;         /* variable for send loop */</div><div><br></div><div>        /* validate number of arguments */</div><div>        if (argv.length != 2) {</div>
<div>                System.out.println(&quot;Usage: mcreceive &quot; +</div><div>                         &quot;&lt;Multicast IP&gt; &lt;Multicast Port&gt;&quot;);</div><div>                System.exit(1);</div><div>         }</div>
<div><br></div><div>        /* validate the multicast address argument */</div><div>        try {</div><div>                mcAddress = InetAddress.getByName(argv[0]);    }</div><div>                catch (UnknownHostException e) {</div>
<div>                System.err.println(argv[0] + &quot; is not a valid IP address&quot;);</div><div>                System.exit(1);</div><div>         }</div><div><br></div><div>        /* validate address argument is a multicast IP */</div>
<div>        if (! mcAddress.isMulticastAddress()) {</div><div>                System.err.println(mcAddress.getHostAddress() +</div><div>                         &quot; is not a multicast IP address.&quot;);</div><div>                System.exit(1);</div>
<div>        }</div><div><br></div><div>        /* parse and validate port argument */</div><div>        try {</div><div>                mcPort = Integer.parseInt(argv[1]);</div><div>        }       catch (NumberFormatException nfe) {</div>
<div>                System.out.println(&quot;Invalid port number &quot; + argv[1]);</div><div>                System.exit(1);</div><div>        }</div><div><br></div><div>        if ((mcPort &lt; MIN_PORT) || (mcPort &gt; MAX_PORT)) {</div>
<div>                System.out.println(&quot;Invalid port number &quot; + mcPort);</div><div>                System.out.println(&quot;Port should be in range &quot; + MIN_PORT</div><div>                         + &quot; to &quot; + MAX_PORT);</div>
<div>                System.exit(1);</div><div>        }</div><div><br></div><div>        try {</div><div><br></div><div>                /* instantiate a MulticastSocket */</div><div>                MulticastSocket sock = new MulticastSocket(mcPort);</div>
<div><br></div><div>                /* set the address reuse option */</div><div>                sock.setReuseAddress(true); // Java 1.4 and higher</div><div><br></div><div>                /* join the multicast group */</div>
<div>                sock.joinGroup(mcAddress);</div><div><br></div><div>                while (!done) {  /* loop forever */</div><div><br></div><div>                        /* create a new DatagramPacket with an empty buffer */</div>
<div>                        byte[] buf = new byte[MAX_LEN];</div><div>                        DatagramPacket packet = new DatagramPacket(buf, buf.length);</div><div><br></div><div>                        /* wait to receive packet into the DatagramPacket instance */</div>
<div>                        sock.receive(packet);</div><div><br></div><div>                        /* output the data from the packet received */</div><div>                        System.out.println(&quot;Received &quot; + packet.getLength() +</div>
<div>                                &quot; bytes from &quot; + packet.getAddress() + &quot;: &quot;</div><div>                                + new String(packet.getData(),0,packet.getLength()));</div><div>                }</div>
<div><br></div><div>                sock.leaveGroup(mcAddress);</div><div>                sock.close();</div><div>        }       catch (IOException e) {</div><div>                System.err.println(e.toString());</div><div>
                System.exit(1);</div><div>                }</div><div>        }</div><div>}</div></div><div><br></div><div>-------------------------------------------------------------------------------------------------------------------<br>
<br><div class="gmail_quote">On Fri, Aug 12, 2011 at 6:00 AM, 이희승 (Trustin Lee) <span dir="ltr">&lt;<a href="mailto:trustin@gmail.com">trustin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

                <div>Could you also post the non-Netty code that works?  I also would suggest you to remove the decoder from the pipeline just in case of the buggy decoder.<br></div>
                <div><br>-- <br><font color="#888888"><a href="http://gleamynode.net/" target="_blank">Trustin Lee</a><br></font></div><div><div></div><div class="h5">
                 
                <p style="color:#A0A0A8">On Thursday, August 11, 2011 at 10:50 PM, alex_ab_sw wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px">
                    <span><div><div>Hello,<br><br>I am trying to write a component in an application that will listen on UDP<br>for multicast messages, but somehow I don&#39;t receive any messages while with<br>a MulticastSocket I can see the messages landing fine.<br>
<br>Here is the piece of code that I am talking about:<br>---------------------------------------------------------------<br>        DatagramChannelFactory channelFactory = new<br>OioDatagramChannelFactory(Executors.newCachedThreadPool());<br>
        ConnectionlessBootstrap bootstrap = new<br>ConnectionlessBootstrap(channelFactory);<br>        <br>        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {<br>            @Override<br>            public ChannelPipeline getPipeline() {<br>
                return Channels.pipeline(messageDecoder, multicastHandler);<br>            }<br>        });<br>        <br>        bootstrap.setOption(&quot;receiveBufferSizePredictorFactory&quot;, new<br>FixedReceiveBufferSizePredictorFactory(<br>
                maxPacketSize));<br>        <br>        <br>        <a href="http://logger.info" target="_blank">logger.info</a>(&quot;... binding the DatagramChannel on new<br>InetSocketAddress {}:{}&quot;, localIpAddress, multicastPort);<br>
        DatagramChannel datagramChannel = (DatagramChannel)<br>        bootstrap.bind(new InetSocketAddress(localIpAddress,<br>multicastPort));<br><br>        try {<br>            InetAddress multicastAddress =<br>InetAddress.getByName(multicastIpAddress);<br>
            datagramChannel.joinGroup(multicastAddress);<br>        } catch (UnknownHostException e) {<br>            shutdown();<br>        }<br>------------------------------------------------------------<br>Can you tell if I am doing something wrong, because I see no errors on logs<br>
but also no messages coming. The component is deployed on a Linux box with<br>CentOS on it.<br><br>Thanks in advance.<br><br>--<br>View this message in context: <a href="http://netty-forums-and-mailing-lists.685743.n2.nabble.com/UDP-Listener-tp6676456p6676456.html" target="_blank">http://netty-forums-and-mailing-lists.685743.n2.nabble.com/UDP-Listener-tp6676456p6676456.html</a><br>
Sent from the Netty User Group mailing list archive at <a href="http://Nabble.com" target="_blank">Nabble.com</a>.<br>_______________________________________________<br>netty-users mailing list<br><a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br></div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>
            </div></div><br>_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>Have fun &amp; travel light.<br>
Alex<br>
</div>