<div><font class="Apple-style-span" face="tahoma, sans-serif"><b><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-size: 13px; font-weight: normal; "><div class="linestyle2 colourline">

Hi,</div><div class="linestyle2 colourline"><br></div><div class="linestyle2 colourline">Explaining the problem in nutshell when I typecast the message (received by the client) to the message type (of protocol buffer class) in the server I get this error WARNING: Unexpected exception from downstream. java.lang.ClassCastException: org.jboss.netty.buffer.BigEndianHeapChannelBuffer cannot be cast to org.jboss.netty.example.echo.MessageProtos$Packet</div>

</span></b><b><span class="Apple-style-span" style="font-size: 13px; font-weight: normal; "><div class="linestyle2 colourline" style="display: inline !important; "><span><span class="Apple-style-span" style="font-size: small; "><b><span class="Apple-style-span" style="font-size: 13px; font-weight: normal; "><div class="linestyle1 colourline" style="display: inline !important; ">

<span>Packet p = (Packet) e.getMessage() , </span></div></span></b></span></span></div></span></b><b><span class="Apple-style-span" style="font-size: 13px; font-weight: normal; "><div class="linestyle2 colourline" style="display: inline !important; ">

<span><meta http-equiv="content-type" content="text/html; charset=utf-8">where Packet is the Message class generated via google Proc Buffers</span></div></span></b></font><b><span class="Apple-style-span" style="font-size: 13px; font-weight: normal; "><div class="linestyle1 colourline">

<br></div></span></b></div><div><b><br></b></div><div><b>SGClienthandler.java : </b></div><div><b><br></b></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>

<span class="Apple-tab-span" style="white-space:pre">        </span>public void send(String message_type, String message_to_send, int message_id){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div>

<span class="Apple-tab-span" style="white-space:pre">                </span>Packet p = Packet.newBuilder()</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>.setPacketId(message_id)</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>.setPacketType(message_type)</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>        .setPacketContent(message_to_send).build();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>try {</div>

<div>            channel.write(p);</div><div>            System.out.print(&quot;Message was sent to this channel : &quot; + channel);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>} </div><div><span class="Apple-tab-span" style="white-space:pre">                </span>catch (Exception e) {</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>System.out.println(&quot; In send() &quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>e.printStackTrace();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div></div></blockquote><div><b>EchoServerhandler.java :</b></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">

<div><div> @Override</div><div>      public void messageReceived(</div><div>              ChannelHandlerContext ctx, MessageEvent e) {</div><div>    <span class="Apple-tab-span" style="white-space:pre">        </span>  System.out.print(&quot;Message Received : &quot; + e.getMessage());</div>

<div>    <span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#ff0000">  Packet req = (Packet) e.getMessage();</font></span></div>

<div>    <span class="Apple-tab-span" style="white-space:pre">        </span>  System.out.print(&quot;Packet Id received  :  &quot; + req.getPacketId());</div><div>    <span class="Apple-tab-span" style="white-space:pre">        </span>  System.out.print(&quot;Packet Type received  :  &quot; + req.getPacketType());</div>

<div>    <span class="Apple-tab-span" style="white-space:pre">        </span>  System.out.print(&quot;Packet Content received  :  &quot; + req.getPacketContent());</div><div><span class="Apple-style-span" style="font-weight: bold; ">     </span>}</div>

</div></blockquote><div><br></div><div><br></div><div>The Pipeline factory of both the client and server namely  : <b>SGPipelineFactory and EchoServerPipelineFactory </b>have same </div><div>encoding and decoding handlers apart from the specific handlers related to their logic.</div>

<blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>     // Decoders</div><div>        pipeline.addLast(&quot;frameDecoder&quot;, new ProtobufVarint32FrameDecoder());</div>

<div>        pipeline.addLast(&quot;protobufDecoder&quot;, new ProtobufDecoder(Packet.getDefaultInstance()));</div><div><br></div><div>        // Encoder</div><div>        pipeline.addLast(&quot;frameEncoder&quot;, new ProtobufVarint32LengthFieldPrepender());</div>

<div>        pipeline.addLast(&quot;protobufEncoder&quot;, new ProtobufEncoder());</div><div>       </div><div>      </div></div></blockquote><div><br></div><div><br></div><br clear="all"><b>Error :</b><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">

<div><div>WARNING: Unexpected exception from downstream.</div><div>java.lang.ClassCastException: org.jboss.netty.buffer.BigEndianHeapChannelBuffer cannot be cast to org.jboss.netty.example.echo.MessageProtos$Packet</div>
<div>
<span class="Apple-tab-span" style="white-space:pre">        </span>at org.jboss.netty.example.echo.EchoServerHandler.messageReceived(EchoServerHandler.java:63)</div></div><div><br></div><div>The line 63 is in red.</div><div><br>

</div><div><br></div><div>Would be great if I can get some pointers.</div></blockquote><div>-- <br>Akash<br><br>
</div>