如何找到服务器不可用的android [英] how to find server unavailable in android

查看:182
本文介绍了如何找到服务器不可用的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林发展具有下载选项的应用程序

Im developing an app which has download option

在通态本地服务器: -

Local Server in OnState:-

从我的Andr​​oid模拟器,我下载的音频文件和它Distination保存路径(本地服务器)
然后,我播放的音频文件,它的工作正确的,
然后我的问题

From My Android Emulator,I Download Audio File and Save it in Distination Path(Local Server), Then I Played the Audio File,it Working Correct, Then My Problem

在OffState本地服务器: -

Local Server in OffState:-

在下载本地服务器,(192.168.0.2/android/a1.mp3(本地服务器路径)),但它是OffState,它仍然显示加载图标..
如何找到Wheather服务器在OffState或通态。
是否有委托连接功能失败,错误

While Downloading Local Server,(192.168.0.2/android/a1.mp3(Local Server Path))But it is OffState,it Still Show Loading Icon.. How Will Find Wheather Server in OffState or Onstate. Is there any delegate functions for connection fail with error

推荐答案

你所需要的是setTimeout的。

What you need here is to setTimeout.

下面code剪断会帮助你。

Below code snipper will help you.

HttpPost httpPost = new HttpPost(url);
    StringEntity se = new StringEntity(envelope,HTTP.UTF_8);
    httpPost.setEntity(se);

    HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    int timeoutConnection = 3000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    // Set the default socket timeout (SO_TIMEOUT) 
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = 3000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
    BasicHttpResponse httpResponse = (BasicHttpResponse)  httpClient.execute(httpPost);

    HttpEntity entity = httpResponse.getEntity();
    return entity;

在这里,如果你没有得到具体的时限内答复。
code会抛出 ConnectTimeoutException

这篇关于如何找到服务器不可用的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆