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/01/11 02:13:39 UTC

Re: Why ConnectFuture.isConnected() returns true while there there is no server?

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 <sq...@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 <he...@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

Re: Why ConnectFuture.isConnected() returns true while there there is no server?

Posted by Ashish <pa...@gmail.com>.
On Mon, Jan 12, 2009 at 9:23 AM, Barrie Treloar <ba...@gmail.com> wrote:
> You probably want to go out and buy "UNIX(R) Network Programming
> Volume 1, Third Edition: The Sockets Networking API" - or use your
> Safari account to read it online.

I would recommend all the three Vols :-)

> Trying to write networking code without understanding the fundamentals
> is a hard task.
> And an email list isn't the best way to impart knowledge.

Well, its a good idea, but lets not put any restrictions on ML. I
believe discussions are the best way to learn.
For ML's, there are many users, who may be willing to help. Let's
leave this to participation.
I have learn't a lot from ML's, which I missed while reading books :-)




-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog

My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: Why ConnectFuture.isConnected() returns true while there there is no server?

Posted by Barrie Treloar <ba...@gmail.com>.
You probably want to go out and buy "UNIX(R) Network Programming
Volume 1, Third Edition: The Sockets Networking API" - or use your
Safari account to read it online.

Trying to write networking code without understanding the fundamentals
is a hard task.
And an email list isn't the best way to impart knowledge.

Re: Why ConnectFuture.isConnected() returns true while there there is no server?

Posted by Squee <sq...@gmail.com>.
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 <he...@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 <sq...@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 <he...@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
>