This is my code :
connection.setConnectTimeout(5000);
ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
out.writeObject(to_be_sent);
out.flush();
out.close();
int resp_code=connection.getResponseCode();
if(resp_code==200)
{
JOptionPane.showMessageDialog(obj.frame, "Your Application has been sent Successfully");
}
As you can see I have set the connection timeout to be 5 seconds. I want to know when this connection time exception is thrown and which line throws it. Is it thrown when connection.getResponseCode() does not return anything for 5 seconds?
Edit
Looked up javadocs just now and found out that getResponse code only throws IOException when not able to connect to the server.
Creating the connection and connecting are a multi-step process, some of the parameters won’t have any effect after performing the connection.
Assuming you are using URLConnection, if you already called connect(), or one of the methods that implicitly perform the connection, it would have no effect at all.
If the connection was made implicitly with getOutputStream method, the exception will be thrown at your second line of code
This throws java.net.SocketTimeoutException if the connection cannot be made in the specified time.
More info about the connect method and setting the connection parameters here