Note that there are some explanatory texts on larger screens.

plurals
  1. POEncoding problem between C# TCP server and Java TCP Client
    text
    copied!<p>i'm facing some encoding issue which i'm not able to find the correct solution.</p> <p>I have a C# TCP server, running as a window service which received and respond XML, the problem comes down when passing special characters in the output such as spanish characters with accents (like á,é,í and others).</p> <p>Server response is being encoded as UTF-8, and java client is reading using UTF-8. But when i print its output the character is totally different.</p> <p>This problem only happens in Java client(C# TCP client works as expected).</p> <p>Following is an snippet of the server code that shows the encoding issue: C# Server</p> <pre><code> byte[] destBytes = System.Text.Encoding.UTF8.GetBytes("á"); try { clientStream.Write(destBytes, 0, destBytes.Length); clientStream.Flush(); }catch (Exception ex) { LogErrorMessage("Error en SendResponseToClient: Detalle::", ex); } </code></pre> <p>Java Client:</p> <pre><code>socket.connect(new InetSocketAddress(param.getServerIp(), param.getPort()), 20000); InputStream sockInp = socket.getInputStream(); InputStreamReader streamReader = new InputStreamReader(sockInp, Charset.forName("UTF-8")); sockReader = new BufferedReader(streamReader); String tmp = null; while((tmp = sockReader.readLine()) != null){ System.out.println(tmp); } </code></pre> <p>For this simple test, the output show is:</p> <pre><code>ß </code></pre> <p>I did some testing printing out the byte[] on each language and while on C# á output as: 195, 161</p> <p>In java byte[] read print as: -61,-95</p> <p>Will this have to do with the Signed (java), UnSigned (C#) of byte type?.</p> <p>Any feedback is greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload