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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

CigarMan

How can I obtain a connection context inside a CallbackHandler?

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

 

Reply | Threaded
Open this post in threaded view
|

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

Jeanfrancois Arcand-2


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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

CigarMan
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.

Simon

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: March-06-08 10:39 AM
To: [hidden email]
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: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Jeanfrancois Arcand-2
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: [hidden email] [mailto:[hidden email]]
> Sent: March-06-08 10:39 AM
> To: [hidden email]
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

CigarMan
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: [hidden email] [mailto:[hidden email]]
Sent: March-06-08 11:36 AM
To: [hidden email]
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: [hidden email] [mailto:[hidden email]]
> Sent: March-06-08 10:39 AM
> To: [hidden email]
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Jeanfrancois Arcand-2


Simon Trudeau wrote:
> 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.
>

This is great!

Thanks!

-- Jeanfrancois


> Simon
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> Sent: March-06-08 11:36 AM
> To: [hidden email]
> 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: [hidden email] [mailto:[hidden email]]
>> Sent: March-06-08 10:39 AM
>> To: [hidden email]
>> 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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]