Hi Ali,

I assume that the getInputStream call is blocking after it is called
and you don't have an internet connection. You might end up in a
deadlock situation.

In case of losing internet connectivity I would have another thread
running which acts on connection state changes.

By the way Android is supporting the Selector class which is similar
to the Posix select.  Get some understanding of the Selector class at

http://developer.android.com/reference/java/nio/channels/Selector.html

--
Roman Baumgaertner
Sr. SW Engineer-OSDC
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.

On Nov 20, 5:44 am, Ali Adnan <akhan.cpr...@gmail.com> wrote:
> Hi,
>
> In my application i get response from web service and show its result
> from resultant stream at activity, i get stream as
>
> try
> {
>         String connectTo = webService + webServiceMethod + queryString;
>         connectTo = connectTo.replaceAll(" ", "%20");
>         URL url = new URL(connectTo);
>         URLConnection ucon = url.openConnection();
>         ucon.setConnectTimeout(15000);
>         ucon.connect();
>         InputStream is = ucon.getInputStream();
>         BufferedInputStream bis = new BufferedInputStream(is);
>         return bis;}
>
> catch (SocketTimeoutException e)
> {
>         throw e;}
>
> catch (MalformedURLException e)
> {
>         throw e;}
>
> catch (IOException e)
> {
>         throw e;
>
> }
>
> If emulator/device is connected with internet then this code work fine
> but if i disconnect internet and try to connect any URL then it keep
> continue to wait even few minutes, however i set connection timeout 15
> seconds. This feel really bad. I want a smart solution, if internet is
> down or disconnected this code will throw SocketTimeOut exception or
> notify me AFTER 15 seconds that net is down.
>
> Ali Adnan.

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to