Dears,

I am writing a server application for some GPS devices and I am having trouble with the receiving data.

The server is working fine, it receives the header as expected and writes to the device, but the data expected to be received is as shown:

Qt Code:
  1. 080400000113fc208dff000f14f650209cca80006f00d6040004000403010115031603000
  2. 1460000015d0000000113fc17610b000f14ffe0209cc580006e00c0050001000403010115
  3. 0316010001460000015e0000000113fc284945000f150f00209cd20000950108040000000
  4. 4030101150016030001460000015d0000000113fc267c5b000f150a50209cccc000930068
  5. 0400000004030101150016030001460000015b0004
To copy to clipboard, switch view to plain text mode 

but the data received is:

Qt Code:
  1. 7811a7b728990508100000001100000098020508000000000000000069000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000058060508000000000000000011000000000000000000000000000000110000006877e3b7000000000000000011000000e874e3b7000000000000000011000000a873e3b7000000000000000011000000a873e3b7010000000000000021000000c80905080040a7b780a2f8b700000000c80905080040a7b780a2f8b71100000002000000010000000000000011000000a873e3b7020000000000000011000000a873e3b7030000000000000039000000c803050802000000c8090508801c5eebe01e5eebd01e5eeb2f7573722f6c69622f67636f6e762f5554462d31362e736f0000000011000000a873e3b7040000000000000011000000a873e3b70500000000000000190000001404050808000000a80c05080900000001000000290000000100000003000000020000000300000001000000e80005083330322f80d4c0b7b4b0e3b711000000a873e3b7060000000000000011000000a873e3b707000000000000003900000001000000040000000300000001000000
To copy to clipboard, switch view to plain text mode 

and the slot (connected to readyRead() signal) that I am handling the received data is as shown:

Qt Code:
  1. // Just for verification
  2. qDebug() << "Bytes Available: " << tcpClient->bytesAvailable();
  3.  
  4. QDataStream in(tcpClient);
  5. quint16 header;
  6.  
  7. in >> header; // reading header
  8.  
  9. char *data = new char[header];
  10.  
  11. // reading raw data on the char pointer above
  12. in.readRawData(data, header);
  13.  
  14. QByteArray b(data, tcpClient->bytesAvailable());
  15.  
  16. // displaying "crazy" data as shown above
  17. printf(b.toHex());
  18.  
  19.  
  20. // sending accepted message to the device
  21. // otherwise the device won't send you the data back
  22. QDataStream out(&ba, QIODevice::WriteOnly);
  23. out << true;
  24.  
  25. tcpClient->write(ba);
To copy to clipboard, switch view to plain text mode 

Any suggestions what I am doing wrong?

Sincerely,
Milot.