Java.net.SocketTimeoutException (ANDROID)

I used the following code to connect -

URL url = new URL("https://results.bput.ac.in/"); HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); urlc.setConnectTimeout(1000 * 20); urlc.connect(); 

He threw a SocketTimeoutException .

Exception

The exact exception that I get is

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

and sometimes it’s

 java.net.SocketTimeoutException: failed to connect to results.bput.ac.in/14.139.212.166 (port 80) after 90000ms 
  • tried to remove urlc.setConnectTimeout(1000 * 20); and still got an exception.
  • verified with http instead of https URL url = new URL("http://results.bput.ac.in/"); but did not get a result.
  • cheked with URL url = new URL("https://www.facebook.com/"); and received a successful response.
  • Checked with a change in the waiting period, but with the same exception.

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

Information

This link I gave http://results.bput.ac.in/ works fine with any web browser without any delay.

I got information that some guys cannot open this site, its lag, but I can open it without any delay.

My research

I already tried this SO question , this SO question , this is a github solution and geeks java code solution , but did not get the result.

Update

I tested this with my Wi-Fi and mobile data, thinking that my router might have problems with the port. but I get the same exception with mobile data too.

Anyone have a solution.

+5
source share
2 answers

If hostname resolves multiple IP addresses, this client will execute each in RFC 3484 . If the connection to each of these addresses fails, several timeouts will occur before the connection attempt makes an exception. Hostnames that support both IPv6 and IPv4 always have at least 2 IP addresses .-- Doc

You have already used setConnectTimeout() and added the maximum time, so do not hesitate. The main reason for SocketTimeoutException is that the timeout expires before the connection is established.

Then the main and specific reason Unable to establish a connection with your server.

+2
source

I tried both https://results.bput.ac.in/ and http://results.bput.ac.in/ and both timeouts. You may not have opened ports 80 and / or 443 in the server firewall.

0
source

Source: https://habr.com/ru/post/1246374/


All Articles