7
Answers

Reading response data in hexa

andrei hooba

andrei hooba

12y
1.5k
1
after i send this packet
byte[] data2 = { 0x00, 0x0E, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x4A, 0x43, 0x50, 0x55, 0x7C, 0x47, 0x45, 0x54 };
stream.Write(data2, 0, data2.Length);
System.Threading.Thread.Sleep(1000);

i'm trying to get some informations from server response.

data2 = new Byte[1024];
bytes = stream.Read(data2, 0, data2.Length);
string responseData = System.Text.Encoding.ASCII.GetString(data2, 0, bytes);
string response = find_str_from_to2(responseData, "galexu", "0|A|CC|");
string intohex = convertAsciiTextToHex(response);

static String convertAsciiTextToHex(String i_asciiText)
  {
  StringBuilder sBuffer = new StringBuilder();
  for (int i = 0; i < i_asciiText.Length; i++)
  {
  sBuffer.Append(Convert.ToInt32(i_asciiText[i]).ToString("x"));
  }
  return sBuffer.ToString().ToUpper();
  }


the problem is that if the responseData is encoded as: ASCII, UTF-8... etc it doesn't get the real information from the server response.

any ideas?

thank you.


Answers (7)