Emmanuel, After debugging more the issue (and correcting the buffer reading code as you described), I finally found the root cause. When reading the header, I (incorrectly) assumed that the header should be contained in a single buffer. I was discarding some bytes of the header buffer that actually belong to the payload (the file being transmitted). This of course, is happening intermittently.
Thanks a lot for your help!, Carlos Alegria On Thu, Jul 31, 2014 at 5:31 PM, Emmanuel Lécharny <elecha...@gmail.com> wrote: > Le 31/07/2014 23:59, Carlos Alegria Galicia a écrit : > > Emmanuel, > > > > Thanks a lot for your answer. After considering your comment and > debugging > > the client-server communication, I found out that, when the issue > "happens" > > (I assume this is happening when session Idle is present and there are > > missing bytes in the state holding object), the server actually reads the > > same amount of bytes sent by the client. > > > > I think then that I am incorrectly reading the input buffer in my > Filter. I > > am currently doing this: > > > > ... > > if (in.hasRemaining()) { > > > > int byteCount = in.limit(); > > byte data[] = new byte[byteCount]; > > in.get(data); > > > > try { > > ctx.out.write(data); > > ctx.bytes -= byteCount; > > } catch (IOException ioe) { > > ctx.out.close(); > > nextFilter.exceptionCaught(session, ioe); > > return; > > } > > > > } > > ... > > > > Is this the proper way of retrieving the data from a buffer? > > Not exactly. Here, you are creating a buffer which will be potentially > too big. You have to take care of the current position in the > ByterBuffer when you compute the length of the buffer. > > Here, you should do something like : > > byte data[] = new byte[in.remaining()]; > in.get(data); > > as explained in > http://docs.oracle.com/javase/7/docs/api/java/nio/Buffer.html#remaining%28%29 > >