You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Hefeng <al...@163.com> on 2010/04/21 12:25:38 UTC
How to make persistent connection from the client side
Hi all,
I’m new to Mina. Recently I’m writing a client program to communicate a
server using persistent connection. I thought I can reuse IoSesssion to
continuously sending message to the server, that’s when a message is sent,
the session is still kept open, and I can send another message with this
open seession. but I obversed that the session will be closed right after
the first message is sent. Here is the code I used to send message and
receive the response in synchronous manner:
session.getConfig().setUseReadOperation(true);
IoBuffer buf = IoBuffer.allocate(2);
buf.put((byte) 0);
buf.put((byte) 0);
buf.flip();
WriteFuture wf = session.write(buf);
wf = wf.awaitUninterruptibly();
if (wf.getException() != null) {
throw wf.getException();
}
ReadFuture readFuture = session.read();
readFuture.awaitUninterruptibly();
if (readFuture.getException() != null) {
throw readFuture.getException();
}
After the first two bytes are sent, if I want to do the same operation by
sending another two bytes, I got a WriteToClosedSessionException.
Can anyone tell me how to prevent the session being close so that I can
create a persistent connection with the server side?
Thank for all your advices.
Hef
RE: How to make persistent connection from the client side
Posted by Hefeng <al...@163.com>.
Ah, how careless I'm. Thanks for the reminder, it was the server who
disconnects the connection. I took almost a half day to research into Mina's
source but found nothing. Thank you very much.
-----Original Message-----
From: users-return-3054-allstuff=163.com@mina.apache.org
[mailto:users-return-3054-allstuff=163.com@mina.apache.org] On Behalf Of
Emmanuel Lecharny
Sent: Wednesday, April 21, 2010 6:50 PM
To: users@mina.apache.org
Subject: Re: How to make persistent connection from the client side
>
> Hi all,
>
> I’m new to Mina. Recently I’m writing a client program to communicate a
> server using persistent connection. I thought I can reuse IoSesssion to
> continuously sending message to the server, that’s when a message is
sent,
> the session is still kept open, and I can send another message with this
> open seession. but I obversed that the session will be closed right after
> the first message is sent. Here is the code I used to send message and
> receive the response in synchronous manner:
>
The session is *not* closed if nobody closes it. Ie, it might be the
server. In this case, that means you have to check on the server side to
see if your message has been correctly processed, or if the server
hasn't closed the session.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com
Re: How to make persistent connection from the client side
Posted by Emmanuel Lecharny <el...@gmail.com>.
>
> Hi all,
>
> I’m new to Mina. Recently I’m writing a client program to communicate a
> server using persistent connection. I thought I can reuse IoSesssion to
> continuously sending message to the server, that’s when a message is sent,
> the session is still kept open, and I can send another message with this
> open seession. but I obversed that the session will be closed right after
> the first message is sent. Here is the code I used to send message and
> receive the response in synchronous manner:
>
The session is *not* closed if nobody closes it. Ie, it might be the
server. In this case, that means you have to check on the server side to
see if your message has been correctly processed, or if the server
hasn't closed the session.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com