HttpURLConnection错误:java.net.SocketTimeoutException:连接超时 [英] HttpURLConnection error: java.net.SocketTimeoutException: Connection timed out

查看:2738
本文介绍了HttpURLConnection错误:java.net.SocketTimeoutException:连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这样简单的urlconnection:

I am using simple urlconnection like this:

       url = URL+"getClient&uid="+cl_id;
        URL url = new URL(this.url);
        Log.d("Set++","get_t URL: "+ url);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

工作正常,但有时我收到此错误:

its working fine, but sometimes i get this error:

       error: java.net.SocketTimeoutException: Connection timed out

可能是什么原因?我只有4个客户......所以我不认为服务器超载连接。

what could be the reason? I have only 4 clients... so i dont think that the server is overloaded with connections.

代码:

    try {
        URL = Settings.BASE_URL + "_interface.php?" +
                "key=" + Settings.KEY +"&app_naam="+Settings.APP_NAAM+ "&action=check&setTime="+c;
        URL url = new URL(URL);
        if(D)Log.e("ChekTreadAanvr+url", URL);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        BufferedReader rd = new BufferedReader(
                new InputStreamReader(conn.getInputStream()));
        String response;
        if ((response = rd.readLine()) != null) {
            rd.close();
        }
        if(D) Log.d("WebSaveThread+","DATARESIEVED:  "+response);
        return response;
            } catch (MalformedURLException e) {
        if(D)Log.d("ERR","server chekc failure ++ ");
        return success = false;
    } catch (IOException ioex) {
        if(D)Log.e("ERR", "error: " + ioex.getMessage(), ioex);
        success = false;
    }
    return Boolean.toString(success);


推荐答案

您的互联网连接速度可能较弱。您可以使用以下方法增加超时间隔。

It may be possible that your Internet Connection Speed is weak. You can increase your Timeout Interval by using following method.

httpURLConnection.setConnectTimeout( 6 * 10 * 1000 ); // One Minute

这篇关于HttpURLConnection错误:java.net.SocketTimeoutException:连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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