Using correct encoding when reading from TCP/Port

264 Views Asked by At

I'm reading a byte stream (byte[]) from a TCP/Port, and converting a subsection of the recieved array into a char[]

Assume that I am not familiar with the characteristics of the port, nor the environment on the other side of this port. All I know is that there is a port.

Part of the data that I recieve is an encoded UK Pound currency symbol (£). When I use ASCII encoding for the conversion, these symbols come through as ?

var charArray = Encoding.ASCII.GetChars(byteArray);

However, when I use UTF-7, all is ok:

var charArray = Encoding.UTF7.GetChars(byteArray);

I should add that when trying UTF-8, this doesn't work.

This was by trial and error, and I'm not entirely sure as to why this might have worked. Rather than just go ahead and deploy a solution, I thought I'd try to understand more as to why this might have worked.

Is it simply that the system on the other side of the port is transmitting in UTF-7, or is there something else going on?

0

There are 0 best solutions below