How to get server message correctly

Posted by Leo on Stack Overflow See other posts from Stack Overflow or by Leo
Published on 2012-11-13T10:26:52Z Indexed on 2012/11/13 11:01 UTC
Read the original article Hit count: 217

Filed under:
|
|

Problem

I send the message "12345" from the socket server to the client:

myPrintWriter.println("12345");

After that I read this message on client:

int c;
while ((c = inputStream.read( )) != -1)
{
    byte[] buffer2 = new byte[1];
    buffer2[0] = (byte) c;
    String symbol = new String(buffer2 , "UTF-8");
    String symbolCode = Integer.toString((int)buffer2[0]);
    Log.v(symbol, symbolCode);
}
Log.v("c == -1", "Disconnected");

What I see in log: enter image description here

With

out.println("abcrefg");

enter image description here

Why? I think it's line termination symbol. I need to get string "12345" or any other and next strings correctly. Help me please.

© Stack Overflow or respective owner

Related posts about android

Related posts about sockets