7

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.

Community
  • 1
  • 1
Sagar Nayak
  • 2,138
  • 2
  • 19
  • 52

2 Answers2

2

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.

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
  • what would i do then ? any solution ? – Sagar Nayak Apr 04 '16 at 04:46
  • Be sure that you can open that `URL` and establish proper connection. your server is not responding but `https://www.facebook.com` will do, so that it's working fine. This means you have nothing to do with this error in client side untill you fix the connection timeout problem. – Shree Krishna Apr 04 '16 at 04:50
  • i have also tried not giving any timeout period and thats giving error too . – Sagar Nayak Apr 04 '16 at 04:56
  • No, that won't work, don't remove that. Just be sure you can open that URL from your device's browser in short duration of time. – Shree Krishna Apr 04 '16 at 04:58
  • If you can smoothly open that from your browser then your code should work fine. But i think it's still lagging. It's not being opened by us. – Shree Krishna Apr 04 '16 at 05:26
  • so if you cant open this link i have given then whats the way to tackle this problem ? because i can open it and you cant but you are saying it is lagging. so should i just increase the timeout period. – Sagar Nayak Apr 04 '16 at 05:39
  • Yah you can try increasing that as well, How much time does it take to open this from your browser ? – Shree Krishna Apr 04 '16 at 05:44
  • instantly opens , and it worst case it open in 1 sec . – Sagar Nayak Apr 04 '16 at 05:45
  • `SocketTimeoutException` means *either* a connect timeout *or* a read timeout. *In this case* it means a connect timeout. – user207421 Apr 04 '16 at 05:50
  • @EJP I am also saying so, *if the timeout elapses before a connection is established.* Then why it's eligible for down? – Shree Krishna Apr 04 '16 at 05:57
0

I tried both https://results.bput.ac.in/ and http://results.bput.ac.in/ and both timed out. Probably you haven't opened ports 80 and/or 443 in the server firewall.

user207421
  • 305,947
  • 44
  • 307
  • 483