What do you mean by "read from a closed session"? I read from the InputStream that I get in the processStreamIo method. Second - while reading from the given InputStream and the socket is closed (the client closes its end), the sessionClosed method is invoked, but the blocked read operation (in a different thread) on the InputStream does not throw any exception.
Please help.

----- Original Message ----- From: "Trustin Lee" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, March 15, 2006 5:18 AM
Subject: Re: how to work with StreamIoHandler


Hi Zohar,

On 3/14/06, Zohar Amir <[EMAIL PROTECTED]> wrote:

Hello,
I have an application that uses StreamIoHandler.  The processStreamIo
method
starts a new thread to handle the incoming data. This thread does
something
like:

  public void run() {
   try {
    while (true) {
     Message message = null;
     message = Decoder.decode(inputStream);
     System.out.print(message);
    }
   } finally {
    session.close();
   }
  }

The questions is how to break the thread loop when the session is closed.
The solution should also handle clients that send short messages, so that
the sessionClosed method is invoked before the thread is started and gets
a
chance to decode the sent message.


If you try to read from a closed session, it should throw an IOException.
So you could simply catch an IOException and break the loop.

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Reply via email to