[Qt-interest] Network file transfer

Shantanu Tushar Jha jhahoneyk at gmail.com
Thu Aug 27 11:24:53 CEST 2009


Hello all,
I want to transfer files (small to huge) over the network using Qt 4.5

Right now, i'm making use of the following steps-
1. Client (QTcpSocket) sends filename to the server (QTcpServer)
2. server creates a thread each "incomingConnection" and the thread sends
"OK<filesize>" if file was found.
3. client receives "OK<filesize>" and sends "SENDDATA" to server
4. server receives "SENDDATA" and sends first 100,000 (100KB) of data to the
client.    ( using socket.write(file.read(100000)) )
5. client gets the data and saves it to a file. then it sends "SENDDATA" to
server    ( using file.write(socket.readAll()) )
6. server receives "SENDDATA" and sends next 100,000 (100KB) of data to the
client, and so on ....
7. client stops after <filesize> bytes have been written

Now, this seems to work randomly sometimes, and at times creating corrupt
transfers. The problem is that the server does send 100000 bytes, but at
times the client receives less than that (i've added to wait till
socket.bytesAvailable() >= 100000 but that never happens in the case). Any
ideas?

Also, to send the file data, i'm right now using
socket.write(file.read(100000)); and for the status strings (e.g. OK) i'm
using socket.write(string.toUtf8());
Should I use QDataStream here ?

Thanks a lot :)

-- 
Shantanu Tushar    (UTC +0530)
http://www.shantanutushar.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090827/3a4cc1bc/attachment.html 


More information about the Qt-interest-old mailing list