I am using nio package to transfer files from client to server. I use jdk1.4.2 on the client side (because have not upgraded our client code to new jre releases) and jdk1.5 on server side (because we use tomcat as webserver and latest tomcat is much stable and scalable but needs jre1.5). I use SocketChannel along with FileChannel to transfer the content of file to the server.
Client code snippet: long bytesRead = fileChannel.transferTo(bytesTransferred, bufferSize, socketChannel);
Server code snippet: long readBytes = fileChannel.transferFrom(socketChannel, 0, m_fileSize);
My problem is that all goes well unless the client machine crashes or the internet goes down, resulting in socketChannel on the client side not getting closed gracefully and hence no exception is thrown on the server sode! So, the thread on the server side that is trying to read from the socketChannel never dies (unless ofcourse webserver is restarted). I am sure I am missing something here, not sure what?
Please look at the following code and let me know what is wrong here! I appreciate you help and thank you for your time.
PS: I have tried to set timeout on socket and that didn't solve my problem and this is my first post so please be gentle, I know it is a big post and my problem could be silly!