Windows service c#
Hi gurus, i have the next problem, my code need send a tcp string, the first 2 bytes of the string are the lenght of the string.
Example:
I have a string of length 690 = 02 b0 in hexadecimal, but the receptor receives 02 C2 B2, whereas it should receive 02 B2.
I have proven in UTF8 encoding and ASCII, but I'm not getting the desired result
Please help me to fix this issue
Thanks for all solutions
// Get the string lenght
char[] lk = ToCharsBitShift(sXMLResponse.Length);
// attach the lenght to the string
sXMLResponse = lk[0].ToString() + lk[1].ToString() + sXMLResponse;
//Encode the string to bytes
Byte[] ClientResponse = Encoding.UTF8.GetBytes(sXMLResponse);
//Send the response to client
clientStream.Write(ClientResponse, 0, ClientResponse.Length);
clientStream.Flush()
public static char[] ToCharsBitShift(int x)
{
char[] chars = new char[2];
chars[1] = (char)(x & 0xFF);
chars[0] = (char)(x >> 8 & 0xFF);
return chars;
}
Open in new window
MessageBox.Show sXMLResponse
just before:
//Send the response to client
clientStream.Write(ClientR
clientStream.Flush()
And post what the first, say 8 characters are...