server = new Socket();
SocketAddress adr = new InetSocketAddress(host,port);
server.connect(adr, 3000);
On 6 Jun., 20:58, JP <[email protected]> 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 <[email protected]> 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 [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
-~----------~----~----~----~------~----~------~--~---