I am trying to send a string containing special characters through TcpClient (byte []). Here is an example:
- Client enters "amé" in the text box
- The client converts the string to byte [] using a specific encoding (I tried all the predefined ones, and some like "iso-8859-1")
- Client sends byte [] over TCP
- The server receives and displays a string converted with the same encoding (to the list)
Edit:
I forgot to mention that the resulting line was "am?".
Edit-2 (as requested here, here is the code):
@DJKRAZE here is some code:
byte[] buffer = Encoding.ASCII.GetBytes("amé"); (TcpClient)server.Client.Send(buffer);
On the server side:
byte[] buffer = new byte[1024]; Client.Recieve(buffer); string message = Encoding.ASCII.GetString(buffer); ListBox1.Items.Add(message);
The line that appears in the list is "am?"
=== Solution ===
Encoding encoding = Encoding.GetEncoding("iso-8859-1"); byte[] message = encoding.GetBytes("babé");
Update:
Just using Encoding.Utf8.GetBytes("ééé"); works like a charm.
source share