android - Socket input stream and Unicode -


I try to write an app that sends text from Windows computer to Android cellphone, the text I send is either English or Hebrew (For example) through the connection socket I use on the Windows Side (Visual Studio 2012):

  string buffer = // some text // data string Encoded in a byte array. Byte [] msg = encoding ASCII.GetBytes (buffer + "\ n"); // Send data via socket Int bytesSent = socketSender.Send (msg);   

and on the Android side:

  // after installing the socket string text = ""; InputStream = socket.getInputStream (); InputStreamReader isr = New InputStreamReader (is); BufferedReader = In the new BufferedReader (ISR); While ((inputText = in.readLine ()) = = null {text = inputText;}   

All this works when texting English. When I try to send Hebrew text I would replace this line:

  byte [] msg = encoding.Unicode.GetBytes (buffer + "\ n");   

But on behalf of Android I can not "read" I tried to use the CharsetEncoder but did not work (or did I do it wrongfully) Any thoughts?

OK The answer is: On the Windows side:

  Byte [] msg = encoding. UTF8. Getbyte (buffer + "\ n");   

and Android side On:

  InputStreamReader isr = New InputStreamReader (is, "UTF-8");    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

java - Session timeout does't work vaadin -