0

Is it possible to read unknown form of data from a QTcpSocket ?

I mean, I have a TCP client and server application. Both are using QDataStream to exchange the data packets successfully.

If say any other application (not created be me) sends data thru the same IP and port to my server, is it possible to read the data ?

I know that unless it's written using QDataStream, it won't be possible to read it, but how do I dump the receiving data so that I can change my code to accept that form of data ?

So, finally my question, how can a server/client application using QTcpSocket read (dump) data from an unknown client/server application ?

Hope I didn't confuse anyone.

Anon
  • 173
  • 2
  • 9

1 Answers1

0

I think the issue is that you're reading with a QDataStream, not that you're using a QTcpSocket. In that case, use readRawData. This will ignore the formatting expected by QDataStream.

http://qt-project.org/doc/qt-4.8/qdatastream.html#readRawData

john.pavan
  • 910
  • 4
  • 6
  • I've tried it. It's reading all the bytes but when I try to display, it's showing nothing. `qDebug() << "Bytes Available: " << client->bytesAvailable();` `QDataStream in(client);` `char raw;` `qDebug() << in.readRawData(&raw, client->size());` – Anon Mar 19 '13 at 03:49
  • 1
    "char raw" is only a single char, but you're reading client->size() bytes. Make that QByteArray raw; raw.resize( client->size() ); readRawData(raw.data(), raw.size()); To print, better use raw.toHex(), as the data might contain non-printable chars. – Frank Osterfeld Mar 19 '13 at 06:17