How to make a socket connection timeout infinity in Servlet doPost method.
843841Sep 27 2007 — edited Sep 27 2007I want to redirect my System.out to a file on a remote server (running Apache Web Server and Apache Tomcat). For which I have created a file upload servlet.
The connection is established only once with the servlet and the System.out is redirected to it. Everything goes fine if i keep sending data every 10 second.
But it is required that the data can be sent to the servlet even after 1 or 2 days. The connection should remain open. I am getting java.net.SocketTimeoutException: Read timed out Exception as the socket timeout occurs.
Can anyone guide me how to change the default timeout of the socket connection in my servlet class.
Following is the coding to establish a connection with the Servlet.
URL servletURL = new URL(mURL.getProtocol(), mURL.getHost(), port, getFileUploadServletName() );
URLConnection mCon = servletURL.openConnection();
mCon.setDoInput(true);
mCon.setDoOutput(true);
mCon.setUseCaches(false);
mCon.setRequestProperty("Content-Type", "multipart/form-data");
In the Servlet Code I am just trying to read the input from the in that is the input stream.
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
BufferedInputStream in = new BufferedInputStream(req.getInputStream());
byte [] content = new byte[1024];
do
{
read = in.read(content, 0, content.length);
if (read > 0)
{
out.write(content, 0, read);
}
}
}
I have redirected the System.out to the required position.
System.setOut(........);
Can anyone guide me how to change the default timeout of the socket connection in my servlet class.