Im my Android app I have a client which has to perform several HTTP requests per second to a server.
I achieve this as follows:
public class myclient implements Runnable {
private HttpClient httpClient = null;
private HttpParams params = null;
private HttpGet httpRequest;
myclient () {
httpClient = new DefaultHttpClient();
params = httpClient.getParams();
httpRequest = new HttpGet(request);
HttpConnectionParams.setConnectionTimeout(params, 60000);
HttpConnectionParams.setSoTimeout(params, 60000);
...
}
@Override
public void run() {
HttpResponse response = httpClient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);
InStream = bufferedHttpEntity.getContent();
...
}
}
Now the problem: while the destination port of each request is the port 80, the local port changes at each request. This causes some trouble with firewalls. Is there some way to keep the local port constant? I solved this porblem in a .NET application setting the local port to a fixed value. But here it seems impossible. Moreover I suppose that the change in local port means a new TCP connection: why the connection is not preserved?