users@grizzly.java.net

RE: Re: [Q] Passing around connection context such as remoteDestinationAddress and LocalSourceAddress

From: Simon Trudeau <strudeau_at_bluetreewireless.com>
Date: Thu, 6 Mar 2008 11:53:17 -0500

Not only will I blog about it but I will write a full tutorial about it! I need to document all that I have learned for the purpose of maintaining my software so I might as well document it so it can benefit the community as well!

I am almost done building my clients, once everything is thoroughly unit tested and benchmarked (yes, I am using Grizzly because it's fast), I will work on the tutorial. It should be done at the end of next week.

Simon

-----Original Message-----
From: Jeanfrancois.Arcand_at_Sun.COM [mailto:Jeanfrancois.Arcand_at_Sun.COM]
Sent: March-06-08 11:36 AM
To: users_at_grizzly.dev.java.net
Subject: Re: [Q] Passing around connection context such as remoteDestinationAddress and LocalSourceAddress

Salut,

Simon Trudeau wrote:
> For all the mailing list readers out there, here's my CallbackHandler onConnect method with Jean-François's recommendation:
>
> public void onConnect(IOEvent<Context> ioEvent) {
> SelectionKey k = ioEvent.attachment().getSelectionKey();
> try {
> connectorHandler.finishConnect(k);
> remoteAddress = ((SocketChannel)k.channel()).socket().getInetAddress();
> localAddress = ((SocketChannel)k.channel()).socket().getLocalAddress();
> if(LOG.isTraceEnabled())
> {
> LOG.trace("connection established from " + localAddress.toString() + " to " + remoteAddress.toString());
> }
> } catch (IOException e) {
> e.printStackTrace();
> }
> ioEvent.attachment().getSelectorHandler().register(k, SelectionKey.OP_READ);
> }
>
> Warning! Make sure you query for the remote and local address AFTER you invoke connectorHandler.finishConnect(k). Or else you will end up with and NPE exception.
>

Might be good if you can blog about your experience :-) What you are
currently building looks quite interesting and I'm sure a lot of users
will be interested to learn :-)

A+

-- Jeanfrancois



> Simon
>
> -----Original Message-----
> From: Jeanfrancois.Arcand_at_Sun.COM [mailto:Jeanfrancois.Arcand_at_Sun.COM]
> Sent: March-06-08 10:39 AM
> To: users_at_grizzly.dev.java.net
> Subject: Re: [Q] Passing around connection context such as remoteDestinationAddress and LocalSourceAddress
>
>
>
> Simon Trudeau wrote:
>> How can I obtain a connection context inside a CallbackHandler?
>
> ((SocketChannel)SelectionKey.channel()).socket().getXXX
>
> Thanks!
>
> -- Jeanfrancois
>
>
>> I would like to know, how can I obtain information about a connection?
>> Most of the time, I will end up passing my connectorHandler around to
>> read and to write, but I don't know how I can get information about the
>> connection such as what's the local port I am connected from and what's
>> the remote port and address I am connected to?
>>
>> Any ideas for me?
>>
>>
>>
>>
>>
>> Simon
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
For additional commands, e-mail: users-help_at_grizzly.dev.java.net