hi,

I have the same problem, but it worked with:

                socket = new Socket();
                SocketAddress adr = new InetSocketAddress(host,port);
                socket.connect(adr, 1000);

  //                      s = new Socket(host, port);
 //                       s.setSoTimeout(1000);


hf

marco

On 6 Jun., 20:58, JP <joachim.pfeif...@gmail.com> wrote:
> I am not familiar with the implementation of the stack, but what you
> could try is to wrap a layer around your calls that first detects
> whether the device is connected to a network. Context.getSystemService
> (CONNECTIVITY_SERVICE) returns an instance of ConnectivtyManager that
> you can query for a NetworkInfo instance. A bit convoluted, but in
> essence if you find that the device is not connected to a network, you
> don't even try to connect and return form the call straight. That
> helped me speed things up. You need an extra permission which you
> declare in the AndroidManifest (I don't have the code with me right
> now but it's easy to find out which).
>
> On Jun 5, 3:46 am, Monkiki <monk...@gmail.com> wrote:
>
> > In the sample code, a SocketTimeoutException should be thrown if the
> > connection can't be stablished in a second, isn't it?
>
> >                 try {
> >                         s = new Socket(host, port);
> >                         s.setSoTimeout(1000);
> >                         if (s.isConnected()) s.close();
> >                 } catch (SocketTimeoutException e) {
> >                         e.printStackTrace();
> >                 } catch (UnknownHostException e) {
> >                         e.printStackTrace();
> >                 } catch (ConnectException e) {
> >                         e.printStackTrace();
> >                 } catch (IOException e) {
> >                         e.printStackTrace();
> >                 }
>
> > But the timeout take a looong time to be detected.

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

Reply via email to