I am working on a project in which I have to get 4096 bytes of data to server from "server" between every 1-millisecond to 10-millisecond. But it's taking too much time i.e around 300ms - 700ms which causes my application to lose data.
I am using below snippet
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("http://192.168.1.40/ping");
HttpResponse response = client.execute(request);
The HttpResponse is only taking too much time i.e around 300ms - 700ms.
How I can get response faster?
Instead of this what else I can use to get a response from server faster then this?
I have done some research, gone through other ways like DataOutputStream
and ByteOutputStream
but no use of this, it also taking too much time then HttpResponse
.
This is not possible. You are recreating a connection every time.
You need to hold a persistent connection with the server. Try creating a persistent http connection.
If that doesn't work you can try sending raw udp packets (or anything else). It will be harder but it will take less time.