store client specific information

Trustin Lee trustin at gleamynode.net
Mon Jan 19 11:30:52 EST 2009


Hi Pete,

Let me assume that you are writing a server and you want to maintain a
map whose key is a user ID (e-mail address) and whose value is a
Channel (connected from a client to the server).

Then, you can simply put a ConcurrentHashMap<String, Channel> field in
your server-side handler (ChannelHandler), and put and remove entries
as clients logs in and out.  To find a Channel associated with an
e-mail address, you can call Map.get() to retrieve the associated
Channel.  Now you can call Channel.write() to send a message to the
client.  Please note that you can call Channel.write() from any
thread, even outside of ChannelHandler's event handler methods because
all methods in Channel are thread-safe - this will give you a lot of
freedom in how you implement your server.

Please feel free to ask more questions if my answer was not clear enough.

HTH,

— Trustin Lee, http://gleamynode.net/



On Sun, Jan 18, 2009 at 9:53 PM, miarkus <miarkus at tlen.pl> wrote:
>
> Hello,
>
> After comparing different java nio socket frameworks I decided to pick Netty
> cause of its great performance. I just need a hint on how to store a client
> ID information (which will be an email address). Let me just say that client
> identifies himself just after establishing connection with server. I should
> be able then to find a specific ID of a client and send him an xml packet.
> Hope this is clear.
>
> Thanks for your help,
>
> Pete
> --
> View this message in context: http://n2.nabble.com/store-client-specific-information-tp2176934p2176934.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
>
> _______________________________________________
> 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