[Qt-interest] Network file transfer

Jeroen De Wachter jeroen.dewachter at barco.com
Thu Aug 27 18:46:44 CEST 2009


QTcpSocket (and, in fact, the OS) should take care of splitting up the
transfer into smaller packets.
There is no 64K limitation mentioned in QTcpSocket's implementation in
any case.

Shantanu:

About: socket.write(file.read(100000));

Do you check the return status of the write call on QTcpSocket? If it
returns -1, there's been an error. This is an often overlooked
mistake...

You should also check the return status on the read call you are doing,
by the way, don't just assume it's completed OK. Check the error()
command on your QFile if the read call returns an empty QByteArray.

I would also suggest just sending the file in its entirety without
sending SENDDATA messages in the "control" channel to regulate the flow
of data.
It's of course fine to buffer only a certain amount of data in the
thread (don't put 2 gigabyte files entirely into memory, for instance),
but there is no reason to communicate between client and server to
notify the client that 100000 bytes are coming...

Don't worry about making sure the bytes get there, the TCP protocol is
designed to be reliable and (in my experience) usually does its job
rather well. Just remember to take into account the return values of the
methods you call on the files/sockets.

Kind regards,

Jeroen

On Thu, 2009-08-27 at 19:36 +0400, Constantin Makshin wrote:
> 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 :)
> 


DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.





More information about the Qt-interest-old mailing list