Results 1 to 2 of 2

Thread: QTcpSocket reading by chunk

  1. #1
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTcpSocket reading by chunk

    Hello,

    With a "classic" network behaviour, a read() function must be -sometimes- called many times because packets aren't delivered in one chunk
    eg:

    Qt Code:
    1. int siz=2048;
    2. int len=siz;
    3.  
    4. while(len>0)
    5. {
    6. siz = read(socket, len); // returns number of bytes read
    7.  
    8. if (siz==0)
    9. return 1;
    10.  
    11. len-=siz;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Now, with QTcpSocket, do I have the same "problem" or a simple
    Qt Code:
    1. sck.read(socket, len);
    To copy to clipboard, switch view to plain text mode 
    is enough to get all the data "len"gth ?


    Thanks
    Last edited by stef13013; 6th September 2012 at 19:44.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket reading by chunk

    As with any other TCP traffic, you have the same "problem". However instead of such a while loop, you should rely on signals emitted by the socket object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTcpSocket can't read all bytes
    By Qiieha in forum Qt Programming
    Replies: 27
    Last Post: 23rd August 2011, 15:48
  2. QtcpSocket read behavior
    By grisson in forum Qt Programming
    Replies: 5
    Last Post: 14th August 2010, 16:31
  3. Replies: 1
    Last Post: 4th September 2009, 09:40
  4. read and write on qtcpsocket
    By dognzhe in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 09:42
  5. Unable to read from QTcpSocket
    By jimroos in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 21:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.