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? Thanks, Carlos Alegria On Thu, Jul 31, 2014 at 2:16 AM, Emmanuel Lécharny <elecha...@gmail.com> wrote: > Le 31/07/2014 03:41, Carlos Alegria Galicia a écrit : > > Hi everyone, > > > > I developed a MINA based client and server to send files over a TCP > > connection. I am using MINA 2.0.7 on both. > > > > - In the client I am sending the file using a header to send file > > properties and FileRegion to actually stream the file. > > - In the server I created a Filter to read the header, and then > receive > > and locally store the file content 'till the expected number of bytes > are > > received. > > > > My problem is that, intermittently, I am not able to receive the last > chunk > > of data from the client. By debugging, I found out that the last chunk is > > actually always shorter than the receive buffer in the server. Is it > > possible that I am not receiving this last chunk because the > > Filter.messageReceived() method is not called on my filter because the > > buffer is not completely filled with data? > > No. As soon as 1 single byte of data is received, a messageReceived > event is generated (but usually, you will get more than 1 byte : you get > as much data as the socket.read() gave). > > You have most certainly some other problem, like your own code is not > calling your handler when it receives less that what the buffer you are > storing the incoming data is expected to hold. > > It's hard to tell without having the entire code of your server. > > Another possibility is that the client is faulty. Are you sure > everything is correctly sent ? At this point, it's a possibility that > the code that manage FileRegion is faulty. A code that reproduces the > problem could help debugging MINA. > > At this point, I would suggest you add a Logger Filter to see if you get > everything on the server side, and that you emit everything on the > client side. > > On my side, I can double check the FileRegion handling in MINA, to be sure. > > >