andrei hooba

andrei hooba

  • NA
  • 63
  • 24k

Reading response data in hexa

Mar 4 2012 7:36 AM
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)