I am attempting to write an application that regularly polls data from
a publicly available website using a URLConnection. The code is
pretty basic (urlStr contains the URL...)
URL url = new URL(urlStr);
URLConnection urlConn = url.openConnection();
urlConn.setConnectTimeout(5000);
BufferedReader in = new BufferedReader(new InputStreamReader
(urlConn.getInputStream()));
String line;
while ((line = in.readLine())!=null) { ....
Anyway, even when the G1 is connected to the network (verified in
browser) this block of code will regularly throw
java.net.SocketException: No route to host,
java.net.SocketTimeoutException: Socket is not connected (though this
is probably because I added a timeout), and many times throw an
Exception claiming that it could not resolve the hostname in urlStr -
oddly the web browser has no such issues resolving the name.
The above block of code runs every 10 seconds (or longer if the
previous request takes longer), and I'd guess succeeds approximately
25-50% of the time, though it tends to be a bit streaky. When the
connection succeeds, it take less than a second to connect and
download the data, it's a very small data set - so the timeout setting
should not be an issue.
The periods of error do not correspond to a loss of connectivity, as I
can browser the web at the same time the errors are happening. This
happens whether connected to local wi-fi or 3G.
Am I doing something wrong, or is network connectivity on the G1 just
this flaky?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---