Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.SocketTimeoutException (ANDROID)

I have used following code to connect -

URL url = new URL("https://results.bput.ac.in/");

HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setConnectTimeout(1000 * 20);

urlc.connect();

It returned a SocketTimeoutException .

Exception

The exact exception i am getting is

java.net.SocketTimeoutException: failed to connect to results.bput.ac.in/14.139.212.166 (port 443) after 90000ms

and sometimes this -

java.net.SocketTimeoutException: failed to connect to results.bput.ac.in/14.139.212.166 (port 80) after 90000ms
  • tried with removing the urlc.setConnectTimeout(1000 * 20); and still got the exception.
  • checked with http instead of https URL url = new URL("http://results.bput.ac.in/"); but got no result.
  • cheked with URL url = new URL("https://www.facebook.com/"); and got success response.
  • Checked with changing the timeout period but same exception .

The problem is with this specific url - http://results.bput.ac.in/ .

Information

This link i have given http://results.bput.ac.in/ is perfectly working on any web browser without any lagging .

I got information that some guys cant open this site , its lagging but i can open it without any lag .

My Research

I have already tried this SO question , this SO question , this github solution and java code geeks solution but got no result.

Update

I have tested this with my wifi and mobile data by thinking that my router might have some problem with the port. but i got same exception with mobile data too.

Do anyone have any solution to this.

like image 736
Sagar Nayak Avatar asked Apr 04 '16 04:04

Sagar Nayak


People also ask

How do I resolve Java net SocketTimeoutException?

Using try/catch/finally. If you are a developer, so you can surround the socket connection part of your code in a try/catch/finally and handle the error in the catch. You might try connecting a second time, or try connecting to another possible socket, or simply exit the program cleanly.

How do I resolve Java net SocketTimeoutException connect timed out?

A possible solution for this problem within the Tomcat web application is to modify the CONTEXT. XML file, and modify the CONNECTOR definition that governs the workstation browser connectivity to the Tomcat server. Specifically, modify the connectionTimeout value. Increase this value to suppress the error condition.

What causes Java SocketTimeoutException?

If the timeout elapses before the method returns, it will throw a SocketTimeoutException. Sometimes, firewalls block certain ports due to security reasons. As a result, a “connection timed out” error can occur when a client is trying to establish a connection to a server.

Why does Java net SocketTimeoutException read timed out?

SocketTimeoutException: Read timed out. This error is typically caused by a maximum concurrent connections limit on the SFTP server itself (either total concurrent connections or concurrent connections from a specific IP).


1 Answers

If the hostname resolves to multiple IP addresses, this client will try each in RFC 3484 order. If connecting to each of these addresses fails, multiple timeouts will elapse before the connect attempt throws an exception. Host names that support both IPv6 and IPv4 always have at least 2 IP addresses.-- Doc

You have already used setConnectTimeout() and added maximum time as well so no doubt on that. The main reason of SocketTimeoutException is if the timeout elapses before a connection is established.

Then the main and certain reason is Connection with your server could not be established.

like image 126
Shree Krishna Avatar answered Oct 09 '22 06:10

Shree Krishna