I'm using Java Socket Programming in order to receive server responses, I'm using a char array
and read each response in it using read()
method:
InputStream stream = null;
try{
stream = socket.getInputStream();
}catch(Exception e){
conn_lost();
}
if(stream != null){
input = new BufferedReader(new InputStreamReader(
stream));
Looper.prepare();
char a[] = new char[1000];
for(int i =0; i < a.length; i++){
a[i] = ' ';
}
while (true){
input.read(a);
String response = String.valueOf(a);
process_server_response(response);
for(int i =0; i < a.length; i++){
a[i] = ' ';
}
}
The problem is some times I can't receive the full response from the server and instead of that I receive like half of it and then the response after that I receive the other half.
Worth to mention:
1- the affected response is a little large that other responses but I'm sure it's not exceed 1000 litters.
2- I'm pretty sure the server-side works perfectly and it sends the responses completed.
3- there isn't any type of terminators exist which could cause that behavior.