Mopparthy Ravindranath
Mopparthy Ravindranath

Reputation: 3308

Netty channelread confusion

I began using Netty 3 months ago. Initially it looked pretty simple and straight forward to use, as I followed the example given in the home page for 4.x series.

As I am exploring it much deeper, I am unable to understand certain events or callback names. For example, I am unable to understand the difference between the following:

ChannelRead(ChannelHandleContext ctx, Object msg) { ... }

channelRead0(ChannelHandlerContext ctx, String message) { ... }

messageReceived(ChannelHandlerContext, I) { ...}

Saw that netty homepage examples always use channelRead, but some examples in internet refer to channelRead0.

Also read that channelRead0 is renamed as messageReceived. If I am writing a simple server program, which one of the above should I use?

Adding to my confusion, I also see Netty packages from JBOss such as

org.jboss.netty.bootstrap.*;

apart from

io.netty.bootstrap.ServerBootstrap;

What is the appropriate way for a newbie to begin and understand netty?

Upvotes: 4

Views: 3963

Answers (1)

hcarrasko
hcarrasko

Reputation: 2352

First, in Netty 3.X the packages were from org.jboss.netty.* see: http://netty.io/3.10/api/index.html But started Netty 4.X the packeages are from io.netty.* see: http://netty.io/4.0/api/index.html

Now, if you are using Netty 4.X to read message use the method

ChannelRead(ChannelHandleContext ctx, Object msg) { ... }

inherited from ChannelInboundHandlerAdapter class. The method:

messageReceived(ChannelHandlerContext, I) { ...}

was used in Netty 3.X version.

EDIT: Adding @trustin (creator of Netty) comment,

channelRead0 is from SimpleChannelInboundHandler of 4.x, and it will be renamed to messageReceived in Netty 5

Hope it helps.

Upvotes: 7

Related Questions