from the Qt Docs:
That does not mean that there aren't more coming.qint64 QAbstractSocket::bytesAvailable () const [virtual]
Returns the number of incoming bytes that are waiting to be read.
from the Qt Docs:
That does not mean that there aren't more coming.qint64 QAbstractSocket::bytesAvailable () const [virtual]
Returns the number of incoming bytes that are waiting to be read.
Do you know while loop??? If the value in the bracket "WHILE(value)" is zero, the loop ends, and when the value greater than zero (that means there are still a data in socket), the loop still work.That does not mean that there aren't more coming.
OK,can u give me a sample code to receive continuous data from socket?
What about forever loop like
for ( ; ; ) {
...
}
or a better representation of it
forever {
...
}
? Is it ok for you?
I'm a rebel in the S.D.G.
I'm a rebel in the S.D.G.
Going back to the op problem:
My answer: ...You have to interpret the length-key of the httpheader somewhere.2.Let the browser (client PC) upload a GIF file to that server. ...
Of cause you can't determine it, if you haven't looked for the header.I can't determine the exactly bytes I expexted, because it is depended on the file I sent...
If you send it via browser POST, then I think you should be able to determine it.
For better understanding: Dump all the data transferred to a text file
and have a look! if there isn't a http-header let us know (and if you post the dump: send the first few bytes only! we don't need the gif-data!)Qt Code:
qDebug << socket->readAll(); // or qDebug << socket->readAll().toHex();To copy to clipboard, switch view to plain text mode
It seems, you haven't understood http (which isn't easy)
These would be suggested resources:
http://www.faqs.org/rfcs/rfc2616.html
http://doc.trolltech.com/4.4/qhttpheader.html
Happy insight!
I can't determine the exactly bytes I expexted, because it is depended on the file I sent. Just give me some example to receive file from another PC, and I will give my highest appreciation to you.You need to send the information how many bytes are to be expected. There is no other reasonable break condition for the loop.![]()
Which is why you need to send it.
I suggest you read the documentation for the fortune client/server example.
Qt Code:
void Server::sendFortune() { QByteArray block; out << (quint16)0; out << fortunes.at(qrand() % fortunes.size()); out.device()->seek(0); out << (quint16)(block.size() - sizeof(quint16)); } void Client::readFortune() { if (blockSize == 0) { if (tcpSocket->bytesAvailable() < (int)sizeof(quint16)) return; in >> blockSize; } if (tcpSocket->bytesAvailable() < blockSize) return; QString nextFortune; in >> nextFortune; }To copy to clipboard, switch view to plain text mode
Bookmarks