[Qt-interest] Network file transfer
Constantin Makshin
dinosaur-rus at users.sourceforge.net
Thu Aug 27 17:36:16 CEST 2009
TCP window size is specified by 2 bytes in the TCP packet header, so the
limit is 64KB. Try sending files in smaller chunks.
On Thu, 27 Aug 2009 13:24:53 +0400, Shantanu Tushar Jha
<jhahoneyk at gmail.com> wrote:
> 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 :)
--
Constantin "Dinosaur" Makshin
More information about the Qt-interest-old
mailing list