Why QTcpSocket read(len) has prefix ?
-
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readMessage())); void MainWindow::readMessage() { qint64 len = tcpSocket->bytesAvailable(); qDebug() << "receive(" << len << ")"; QByteArray BA = tcpSocket->read(len); qDebug() << "ByteArray(" << BA << ")"; }old.htm (file name)
ByteArray( "\x00\x07old.htm" )file content
ByteArray( "\x00\x00\x00\x00\x00\x00\b\xA2<html>\n......" ) -
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readMessage())); void MainWindow::readMessage() { qint64 len = tcpSocket->bytesAvailable(); qDebug() << "receive(" << len << ")"; QByteArray BA = tcpSocket->read(len); qDebug() << "ByteArray(" << BA << ")"; }old.htm (file name)
ByteArray( "\x00\x07old.htm" )file content
ByteArray( "\x00\x00\x00\x00\x00\x00\b\xA2<html>\n......" )@sonichy Please explain what you mean. What prefix?
Also, don't forget that the data you're sending can arrive in several packets. That means: tcpSocket->read(len) does not necessarily return the whole package you sent. You need to accumulate data in a QByteArray until you notice that you got whole package. -
@sonichy Please explain what you mean. What prefix?
Also, don't forget that the data you're sending can arrive in several packets. That means: tcpSocket->read(len) does not necessarily return the whole package you sent. You need to accumulate data in a QByteArray until you notice that you got whole package.@jsulm said in Why QTcpSocket read(len) has prefix ?:
@sonichy Please explain what you mean. What prefix?
He (claims he) is sending
old.htmbut receiving\x00\x07old.htm.