[Qt-interest] Fwd: Network file transfer

Jeroen De Wachter jeroen.dewachter at barco.com
Thu Aug 27 19:09:55 CEST 2009


If no errors occur while writing the data, I suggest putting some
debugging statements over the course of your program and find out where
it goes wrong... (#bytes sent, #bytes received, etc.) I think it's safe
to assume the TCP connection will not lose any bytes.

Yes, just keep reading 100000 bytes and writing them in a loop until the
entire file is sent.

One thing you could do, perhaps, is provide some inter-thread
communication to have the thread cancel the transfer when necessary
(when the server is shutting down, for instance). For example, your
thread could check some variable between each write call to see if it
should continue or abort (you might want to set the timeout on the
socket to a proper value as well when you do this...).

On Thu, 2009-08-27 at 22:23 +0530, Shantanu Tushar Jha wrote:
> Oops, i forgot to cc the mailing list.
> 
> On Thu, Aug 27, 2009 at 10:16 PM, Jeroen De Wachter
> <jeroen.dewachter at barco.com> wrote:
>         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...
>  
> yes, it returns 100000 only. 
> 
>         
>         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.
> 
> Then should i just keep executing socket.write(data) (where data is
> some 100000 bytes) in a loop until whole file is transferred ? 
> just for info, this is for a LAN, so no speed problems.
> 
> 
>         
>         
>         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.
>         
>         
>         
>         _______________________________________________
>         Qt-interest mailing list
>         Qt-interest at trolltech.com
>         http://lists.trolltech.com/mailman/listinfo/qt-interest
>         
> 
> 
> 
> 
> -- 
> Shantanu Tushar    (UTC +0530)
> http://www.shantanutushar.com
> 
> 
> 
> 
> -- 
> Shantanu Tushar    (UTC +0530)
> http://www.shantanutushar.com
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest


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