java.net.SocketTimeoutException (ANDROID)
Asked Answered
C

2

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.

Circumgyration answered 4/4, 2016 at 4:35 Comment(4)
is that link working ?Cadel
i have edited my question. @PankajNimgade the link works.Circumgyration
i tried that link in browser, but it times out, are you sureCadel
i tried it now @PankajNimgade and this took like 1 sec to load .Circumgyration
E
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.

Eley answered 4/4, 2016 at 4:43 Comment(10)
what would i do then ? any solution ?Circumgyration
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.Eley
i have also tried not giving any timeout period and thats giving error too .Circumgyration
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.Eley
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.Eley
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.Circumgyration
Yah you can try increasing that as well, How much time does it take to open this from your browser ?Eley
instantly opens , and it worst case it open in 1 sec .Circumgyration
SocketTimeoutException means either a connect timeout or a read timeout. In this case it means a connect timeout.Hinda
@EJP I am also saying so, if the timeout elapses before a connection is established. Then why it's eligible for down?Eley
H
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.

Hinda answered 4/4, 2016 at 5:50 Comment(1)
how do i do that ?Circumgyration

© 2022 - 2024 — McMap. All rights reserved.