Friday 15 April 2011

android - Socket input stream and Unicode -



android - Socket input stream and Unicode -

i seek write app sends text windows computer android cellphone. text send can in english language or hebrew (for example). connection via socket. code utilize on windows side (visual studio 2012):

string buffer = // text // encode info string byte array. byte[] msg = encoding.ascii.getbytes(buffer + "\n"); // send info through socket. int bytessent = socketsender.send(msg);

and on android side:

//after found socket string text = ""; inputstream = socket.getinputstream(); inputstreamreader isr = new inputstreamreader(is); bufferedreader in = new bufferedreader(isr); while ((inputtext = in.readline()) != null) { text = inputtext; }

all works when sending english language text. when seek send hebrew text replace line:

byte[] msg = encoding.unicode.getbytes(buffer + "\n");

but on android side can't "read" it. tried utilize charsetencoder didn't work (or did wrong way). ideas?

ok, reply is: on windows side:

byte[] msg = encoding.utf8.getbytes(buffer + "\n");

and on android side:

inputstreamreader isr = new inputstreamreader(is, "utf-8");

android sockets unicode inputstream

No comments:

Post a Comment