Can anyone give me a sample program how to receive a binary files over TCP using QSocket or other similar class?
Thx in advance..
Can anyone give me a sample program how to receive a binary files over TCP using QSocket or other similar class?
Thx in advance..
Thanks but I still have a problem. I'll let u know my project is:
1.Build a Simple HTTP Server on embedded device so that a browser can connect and receive a HTML page.(done)
2.Let the browser (client PC) upload a GIF file to that server. I use FrontPage2003 to develop a HTML script and FileUpload Component from FrontPage2003. (not done yet)
The problem is my embedded device can't receive the whole packets transfered, it only can receive some part of the file.
Do u have any solution??
Thx in advance.
Why? buffer to small in the embedded device? Where happens the fragmentation?The problem is my embedded device can't receive the whole packets transfered, it only can receive some part of the file.
This is my read socket procedure:
Qt Code:
while (socket->bytesAvailable()) { myfile.writeBlock(socket->readAll()); myfile.flush(); socket->waitForMore(1); }To copy to clipboard, switch view to plain text mode
When I simulated this program on PC (using localhost address 127.0.0.1), I can get the whole part of the file I sent. But unfortunately I can't do that for my embedded device.
Any suggestion??
Thx for reply
Last edited by jpn; 29th May 2008 at 13:11. Reason: missing [code] tags
maybe I'm missing something...You have to interpret the length-key of the httpheader somewhere.
Maybe I should try to find another way...
Do you understand the problem?Maybe I should try to find another way...
Example:
the file size is 100.000 Bytes
the 1st tcp/ip paket has 50.000 Bytes, when it arrives it triggers your slot, you read it, and think that was all
in the meantime the 2nd paket arrives, but you don't expect it, you think that all the data has been send in the first paket which triggert the slot.
Understandable?
Look at my program:
Qt Code:
while (socket->bytesAvailable()) // In this loop, I wait for new incoming packet until no packet arrived anymore { myfile.writeBlock(socket->readAll()); myfile.flush(); socket->waitForMore(1); }To copy to clipboard, switch view to plain text mode
Last edited by jpn; 29th May 2008 at 13:11. Reason: missing [code] tags
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?
Bookmarks