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? If this is the case, how can I tell MINA to expect a message shorter than the receive buffer (is session.getConfig().setReadBufferSize() a correct way to do this) ? I am posting my server buffer reading code if is of any help: ----------------------------- ..... Context ctx = (Context) session.getAttribute(CONTENT); // // saving bytes, if available // 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; } } session.getConfig().setReadBufferSize(readBufferSize); // // check if file is complete // if (ctx.bytes <= 0) { ctx.out.close(); nextFilter.messageReceived(session, ctx.file); } -------------------------------------- Thanks in advance