1
我使用Apache httpclient 4.0通过HTTP连接到视频流(运动jpeg)。这是我的代码:Apache httpclient使大量的连接
DefaultHttpClient client;
HttpParams params = new BasicHttpParams();
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.DIGEST);
authpref.add(AuthPolicy.BASIC);
params.setParameter("http.auth.proxy-scheme-pref", authpref);
params.setParameter("http.protocol.handle-authentication", Boolean.TRUE);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager connectionManager =
new ThreadSafeClientConnManager(params, schemeRegistry);
client = new DefaultHttpClient(connectionManager, params);
client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, password));
HttpResponse videoResponse = client.execute(new HttpGet(url));
问题是,client.execute()行似乎使数百连接到视频流。我可以通过登录到服务器并执行netstat来看到这一点:有80个端口的连接数量很大,并且都处于TIME_WAIT状态。
我在这里做错了什么?这是怎么回事?
感谢您的帮助。
裁判只是说如何直接使用HttpClientConnection时释放的连接,但没有关于发布从HttpClient的连接。 – 2015-10-07 19:51:04