6 Replies Latest reply: Mar 15, 2011 1:09 PM by jschellSomeoneStoleMyAlias RSS

    JAVA IOException uncatched

    847247
      Hi, I'm using Java.nio channels and when one client was forced to disconnect to my host, my host launch that exception:



      java.io.IOException: Se ha forzado la interrupción de una conexión existente por el host remoto
           at sun.nio.ch.SocketDispatcher.read0(Native Method)
           at sun.nio.ch.SocketDispatcher.read(Unknown Source)
           at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
           at sun.nio.ch.IOUtil.read(Unknown Source)
           at sun.nio.ch.SocketChannelImpl.read(Unknown Source)

      The Code is this:

      if (key.isReadable()) {

                                         SocketChannel client = (SocketChannel) key
                                                   .channel();

                                         // Create buffer to read
                                         int BUFFER_SIZE = 2000;
                                         ByteBuffer buffer = ByteBuffer
                                                   .allocate(BUFFER_SIZE);

                                              byte[] aReceivedByteArray = new byte[2000];
                                                   ByteBuffer.wrap(aReceivedByteArray);


                                              try{

                                              client.read(buffer);+*
                                              }
                                              catch (IOException e){
                                                   System.out.println("I'ts disconnected");
                                                   client.close();
                                                   e.printStackTrace();
                                                   continue;     
                                                   
                                              }

      I don't know why the catch statement is not catching that exception.
      I've tryed to move the try/catch statements to some other lines, but always the IOexception is lunched.
      Can somebody help me how to solve that problem?

      thanks.

      /Genís.

      P.D. I think I have post in a wrong part of the forum, sorry for that.

      Edited by: 844244 on 14/03/2011 10:36