mina-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Squee <squees...@gmail.com>
Subject Re: Why ConnectFuture.isConnected() returns true while there there is no server?
Date Mon, 12 Jan 2009 10:26:48 GMT
Again, haven't used MINA's UDP support yet, but here's what my
understanding would be.

Using the connector to connect, the session will be opened when the
connect() is called. There is no need for negotiations with the remote
host, so the session can be opened immediately to allow writes to the
remove host. Closed will only be called when you have explicitly
called close() on the session. Since various router firewalls use the
strategy of keeping open a UDP port for the live "connection," I
assume this is similar.

If you are using a DatagramAcceptor, then yes a sesssionOpened() call
will occur when it receives a packet from a host. Again, similar to
the firewall strategy, further communications from the same remote
host would happen on that session. And, again, the session would need
to be closed manually.

This is what I assume since it most closely mirrors TCP behavior in
MINA, without the connection portion.

Also, as with any future, if the future has already happened, await()
will return immediately and added listeners will run as soon as they
are added. I believe you can still use those on UDP. Since the
ConnectFuture is the only way to get a session object to write to the
remote host, it's still going to be useful.

On Sat, Jan 10, 2009 at 6:13 PM, hezjing <hezjing@gmail.com> wrote:
> Hi
> I'm sorry, but I'm confused with UDP again ...
>
> Since UDP is a connectionless protocol, does that also means the
> ConnectFuture is not applicable to NioDatagramConnector?
> For example, there is no use to program ConnectFuture like the following?
>
> NioDatagramConnector connector = new NioDatagramConnector();
> ConnectFuture future = connector.connect(new InetSocketAddress(hostname,
> port));
> future.awaitUninterruptibly();
> future.addListener(...);
>
>
> Then, when is the IoHandler.sessionOpened() and IoHandler.sessionClosed()
> are being called for UDP?
> My guess is the sessionOpened() will be called when the very 1st UDP packet
> is received (??),
> but the sessionClosed() will be called when ... ???
>
>
> On Mon, Dec 29, 2008 at 5:14 PM, Squee <squeeself@gmail.com> wrote:
>
>> While I've never actually used Mina's UDP yet, you need to keep in
>> mind that UDP doesn't use connections. I believe the Datagram
>> connector simply does nothing when you "connect" with it; no traffic
>> is sent to the server. So, a UDP session will always be "connected"
>> and a connect attempt will always be successful. Or at least, that's
>> what I assume.
>>
>> If you need to know whether you've successfully connected to a server,
>> use TCP instead (NioSocketConnector).
>>
>> On Sun, Dec 28, 2008 at 9:59 AM, hezjing <hezjing@gmail.com> wrote:
>> > Hi
>> >
>> > I have a method to connect to a UDP server,
>> >
>> > private void connect(String hostname, int port) {
>> >        logger.debug("Entered connect()");
>> >        NioDatagramConnector connector = new NioDatagramConnector();
>> >        ConnectFuture future = connector.connect(new
>> > InetSocketAddress(hostname, port));
>> >        future.awaitUninterruptibly();
>> >        future.addListener(new IoFutureListener<ConnectFuture>() {
>> >            public void operationComplete(ConnectFuture future) {
>> >                if (future.isConnected()) {
>> >                    logger.debug("...connected");
>> >                } else {
>> >                    logger.error("Not connected...exiting");
>> >                }
>> >            }
>> >        });
>> >        logger.debug("Exiting connect()");
>> > }
>> >
>> >
>> > when run without starting any UDP server (on Windows XP), the program
>> prints
>> > the following on the console
>> >
>> > Entered connect()
>> > ...connected
>> > Exiting connect()
>> >
>> >
>> > Why future.isConnected() returned true while there isn't any server
>> running?
>> >
>> >
>> > --
>> >
>> > Hez
>> >
>>
>
>
>
> --
>
> Hez
>

Mime
View raw message