You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by hezjing <he...@gmail.com> on 2009/03/06 11:20:09 UTC
NioDatagramAcceptor.newSession
Hi
I have the following scenario:
1. Peer A connects to Peer B.
2. Peer A sends Alive request to Peer B (once it is connected to Peer B).
3. Peer B replies Peer A with a Alive response.
4. For every specific interval, Peer A keep sending Peer B a Hello request.
Peer B replies Peer A with a Hello response.
Here is what I implemented Peer A, for step 1 and 2:
NioDatagramAcceptor acceptor = new NioDatagramAcceptor();
...
acceptor.bind(new InetSocketAddress(peerBPort));
// obtain a session in order to send the first Alive request
IoSession session = acceptor.newSession(new
InetSocketAddress(InetAddress.getByName(peerBIp), peerBPort), new
InetSocketAddress(peerAPort));
...
WriteFuture future = session.write(aliveRequest);
future.awaitUninterruptibly();
This program is working so far, but is this the correct way of doing thing?
Can we call newSession many times as we want?
I hope we can improve the javadoc of NioDatagramAcceptor, there is no
description for NioDatagramAcceptor.newSession().
See
http://mina.apache.org/report/trunk/apidocs/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.html
--
Hez
Re: NioDatagramAcceptor.newSession
Posted by hezjing <he...@gmail.com>.
Hi
I'm sorry for my mistake, and here is what I should do ...
To implement Peer A, I should really use NioDatagramConnector instead
of NioDatagramAcceptor.
To connect to Peer B, I should call
connector.connect(new InetSocketAddress(peerAIp, peerBPort), new
InetSocketAddress(peerAIp, peerAPort));
To implement step 2. Peer A sends Alive request to Peer B (once it is
connected to Peer B), I should send the request in sessionOpened(IoSession
session).
Sorry!
On Sat, Mar 7, 2009 at 1:56 AM, hezjing <he...@gmail.com> wrote:
> Hi Erix,
>
> Yes, I read the UDP tutorial in the Mina website.
> Can you explain why we cannot use Mina for this implementation?
>
>
> Hi Emmanuel,
>
> In fact, Peer B is a legacy program implemented by a vendor.
> We have to configure Peer A's address and port (in my example, peerAPort)
> in Peer B, otherwise Peer B will complaint the un-configured connection.
>
> I tried without the NioDatagramAcceptor.newSession(), but Peer B couldn't
> recognize Peer A because the local port was varied for every connection.
> Is there a way to specify the local address & port of NioDatagramAcceptor?
>
> For some reasons, it seems that the NioDatagramAcceptor.newSession() is
> able to set the local address & port of NioDatagramAcceptor.
>
>
>
> On Fri, Mar 6, 2009 at 7:11 PM, Emmanuel Lecharny <el...@apache.org>wrote:
>
>>
>> I hope we can improve the javadoc of NioDatagramAcceptor, there is no
>>> description for NioDatagramAcceptor.newSession().
>>> See
>>>
>>> http://mina.apache.org/report/trunk/apidocs/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.html
>>>
>>>
>> I'm adding the missing references to the interface's doc. Thanks for
>> having reported this lack of doco !
>>
>> Regarding your question, why don't you reuse the session you have created,
>> instead of creating a new one each time ? Creating a session is an expensive
>> operation ...
>>
>> --
>> --
>> cordialement, regards,
>> Emmanuel Lécharny
>> www.iktek.com
>> directory.apache.org
>>
>>
>>
>
>
> --
>
> Hez
>
--
Hez
Re: NioDatagramAcceptor.newSession
Posted by hezjing <he...@gmail.com>.
Hi Erix,
Yes, I read the UDP tutorial in the Mina website.
Can you explain why we cannot use Mina for this implementation?
Hi Emmanuel,
In fact, Peer B is a legacy program implemented by a vendor.
We have to configure Peer A's address and port (in my example, peerAPort) in
Peer B, otherwise Peer B will complaint the un-configured connection.
I tried without the NioDatagramAcceptor.newSession(), but Peer B couldn't
recognize Peer A because the local port was varied for every connection.
Is there a way to specify the local address & port of NioDatagramAcceptor?
For some reasons, it seems that the NioDatagramAcceptor.newSession() is able
to set the local address & port of NioDatagramAcceptor.
On Fri, Mar 6, 2009 at 7:11 PM, Emmanuel Lecharny <el...@apache.org>wrote:
>
> I hope we can improve the javadoc of NioDatagramAcceptor, there is no
>> description for NioDatagramAcceptor.newSession().
>> See
>>
>> http://mina.apache.org/report/trunk/apidocs/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.html
>>
>>
> I'm adding the missing references to the interface's doc. Thanks for having
> reported this lack of doco !
>
> Regarding your question, why don't you reuse the session you have created,
> instead of creating a new one each time ? Creating a session is an expensive
> operation ...
>
> --
> --
> cordialement, regards,
> Emmanuel Lécharny
> www.iktek.com
> directory.apache.org
>
>
>
--
Hez
Re: NioDatagramAcceptor.newSession
Posted by Emmanuel Lecharny <el...@apache.org>.
> I hope we can improve the javadoc of NioDatagramAcceptor, there is no
> description for NioDatagramAcceptor.newSession().
> See
> http://mina.apache.org/report/trunk/apidocs/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.html
>
I'm adding the missing references to the interface's doc. Thanks for
having reported this lack of doco !
Regarding your question, why don't you reuse the session you have
created, instead of creating a new one each time ? Creating a session is
an expensive operation ...
--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org
Re: NioDatagramAcceptor.newSession
Posted by Erix Yao <er...@gmail.com>.
I think you should see the examples available in the apache site.I don't
think you can use Mina in this way.
2009/3/6 hezjing <he...@gmail.com>
> Hi
>
> I have the following scenario:
>
> 1. Peer A connects to Peer B.
> 2. Peer A sends Alive request to Peer B (once it is connected to Peer B).
> 3. Peer B replies Peer A with a Alive response.
> 4. For every specific interval, Peer A keep sending Peer B a Hello request.
> Peer B replies Peer A with a Hello response.
>
>
> Here is what I implemented Peer A, for step 1 and 2:
>
> NioDatagramAcceptor acceptor = new NioDatagramAcceptor();
> ...
> acceptor.bind(new InetSocketAddress(peerBPort));
>
> // obtain a session in order to send the first Alive request
> IoSession session = acceptor.newSession(new
> InetSocketAddress(InetAddress.getByName(peerBIp), peerBPort), new
> InetSocketAddress(peerAPort));
> ...
> WriteFuture future = session.write(aliveRequest);
> future.awaitUninterruptibly();
>
>
> This program is working so far, but is this the correct way of doing thing?
> Can we call newSession many times as we want?
>
> I hope we can improve the javadoc of NioDatagramAcceptor, there is no
> description for NioDatagramAcceptor.newSession().
> See
>
> http://mina.apache.org/report/trunk/apidocs/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.html
>
>
> --
>
> Hez
>