I am experiencing a strange situation.
I have two applications: client side socket in Android and Java socket server runs the server in the context of application startup.
Between the client and the server are sent using JSON STRING URLEncoder in each field that is to avoid string parsing to JSON.
If sent from client to server in JSON STRING reached only 1 post. When I try to send the second is not sent to the server. It is somewhere you know.
Now if STRING shipping without any special formatting eg ABCDEFG12331 always arrive at the server.
example how client sent or server response:
byte[] data = strText.getBytes("UTF-8");
DataOutputStream d = new DataOutputStream(wsSocket.getOutputStream());
d.write(data);
d.flush();
example how client read or server read
int maxBuffer = Math.max(wsIS.available(), 8192);
byte[] buffer = new byte[maxBuffer];
int size = wsIS.read(buffer);
if (size == -1) {
break;
}
StringBuilder str = new StringBuilder();
str.append(new String(buffer, "UTF-8").substring(0, size).trim());
Since you haven’t mentioned much about the code,
One thing that both client and server should follow in this case is to use
BufferedReader/Writerand should the data channel being left open should then allow the strings to read after everyflush().Also, make sure that
close()is not being called at any time.Another pointer is – at server end once you get the client connection, then preserve the reference of the inputStream and outputStream, since these must be used whenever the data exchange happens. Otherwise, from any other new reference, you would not be able to perform the operation