Stop receiving requests

Johnny Luong johnny.luong at trustcommerce.com
Wed May 12 21:33:59 EDT 2010


Hi Shay,

I think the example provided in the javadoc under Decoder Implementation 
is what your trying to do and provides clarity...

http://docs.jboss.org/netty/3.1/api/

Best,
Johnny


Shay Banon wrote:
> Hi,
> 
>    I have a problem and am trying to find the best solution for. In netty, I
> am using a FrameDecoder that simply does the following:
> 
>     protected Object decode(ChannelHandlerContext ctx, Channel channel,
> ChannelBuffer buffer) throws Exception {
> 
>         if (buffer.readableBytes() < 4) {
>             return null;
>         }
> 
>         int dataLen = buffer.getInt(buffer.readerIndex());
>         if (dataLen <= 0) {
>             throw new StreamCorruptedException("invalid data length: " +
> dataLen);
>         }
> 
>         if (buffer.readableBytes() < dataLen + 4) {
>             return null;
>         }
> 
>         buffer.skipBytes(4);
> 
>         return buffer;
>     }
> 
> On the next handler, I use the buffer to extract the request from (and other
> information). The problem I have is that something might fail and I won't
> read the whole buffer. In this case, things gets corrupted for requests that
> follow. Once I do read the whole buffer, things works correctly. I can
> skipBytes in the size of (writerIndex - readerIndex) in case of an
> exception, but then I wonder how does the built in ObjectDecoder handles
> this case..., maybe I am missing something?
> 
> cheers,
> shay.banon
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users



More information about the netty-users mailing list