http connection timeout issues

前端 未结 10 1588
感情败类
感情败类 2020-12-13 20:54

I\'m running into an issue when i try to use the HttpClient connecting to a url. The http connection is taking a longer time to timeout, even after i set a connection timeoo

10条回答
  •  孤城傲影
    2020-12-13 21:12

    Not sure if this helps you, however I think it's worth sharing here. While playing with the timeout stuff I found there is a third timeout type you can assign:

    // the timeout until a connection is established
    private static final int CONNECTION_TIMEOUT = 5000; /* 5 seconds */
    
    // the timeout for waiting for data
    private static final int SOCKET_TIMEOUT = 5000; /* 5 seconds */
    
    // ----------- this is the one I am talking about:
    // the timeout until a ManagedClientConnection is got 
    // from ClientConnectionRequest
    private static final long MCC_TIMEOUT = 5000; /* 5 seconds */
    
    ...
    
    HttpGet httpGet = new HttpGet(url);
    setTimeouts(httpGet.getParams());
    
    ...
    
    private static void setTimeouts(HttpParams params) {
        params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 
            CONNECTION_TIMEOUT);
        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT);
        params.setLongParameter(ConnManagerPNames.TIMEOUT, MCC_TIMEOUT);
    }
    

提交回复
热议问题