Can't find appropriate examples of what I'm trying to achieve with Netty

Christian Migowski chrismfwrd at gmail.com
Fri May 29 05:26:14 EDT 2009


Hi NiPNi,

On Fri, May 29, 2009 at 10:13 AM, NiPNi <nils-petter at nilsen.as> wrote:
>
[...]
> I'm having some difficulties formulating the actual question here, because
> this is all new to me (I usually work at a higher level, with webapps and
> JBoss and such).
>
> My main issue, I think, is the fact that the response to a request is
> produced asynchronously, so that from Netty's point of view, it's not a
> response per se, but rather an unsolicited message initiated from the server
> side.
>
> This means that I have to keep track of the connections. The clients do have
> a logical ID that will be used in the higher-level applications, so I can
> use that as a key to map the connections, but I don't have a clue what to
> map.

Each channel (which is a tcp or udp connection) has an ID (getId()),
you should map your logical ID to the channel ID. If you use a
ChannelGroup (see the Javadoc, it is pretty good) you can get the
client connection (Channel) back using its ID and send back the
response.

> What I'm looking for with this post are actually two things
> - a confirmation that this sort of server is even possible to make with
> Netty

sure, most certainly!

> - a pointer or example on how to attack this problem; the examples I've
> found are good, but too simple to be of much help given my limited
> experience in this field

see above.
- Store the channel in the ChannelGroup when channelConnected() is
called by netty
- store the mapping of the Channel ID and your ID when you get your
logical ID (when messageReceived() is called)
- when your backend processing is done, get the channel id from your
mapping, with that Id get the channel from ChannelGroup
- use the channel to send back the reply

Hth,
regards,
christian!



More information about the netty-users mailing list