Results 1 to 5 of 5

Thread: Big buffer over TCP Socket

  1. #1
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Big buffer over TCP Socket

    Hi i am making stream from mobile to PC. In device i use Java app which send a byte array (of a Opencv Mat object) and then it say the array over TCP and on PC i have an Qt app which receive socket and then just show lenght of received data. Data's lenght should be 25 344 but in Qt app:
    Qt Code:
    1. void Server::readyRead()
    2. {
    3. QByteArray byte = socket->readAll();
    4. qDebug() << byte.size();
    5.  
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 
    i get 18 lines: On 17 lines is 1448 and on one is 728
    when i count it its 25 344 but why it send it like that. From java i send only one message but in Qt it looks like i sent 18 messages
    why? Is it the big size of message?
    Thanks

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

    Default Re: Big buffer over TCP Socket

    With TCP there is no concept of "messages", just a stream of bytes. The fact that in Java you receive the data in one go is purely incidental, you might as well receive it in 25344 parts. It is your responsibility to detect the end of "message", assemble the data and make use of it.
    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.


  3. The following user says thank you to wysota for this useful post:

    Viper666 (14th November 2013)

  4. #3
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Big buffer over TCP Socket

    So if i understand there is no other option just add something with which i will detect the end of stream. Ok thanks for response

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Big buffer over TCP Socket

    Typically sending a 4 or 8 byte packet size first, buffering bytes (in a QByteArray or on disk) until that number has been reached, processing the packet, and removing the packet from the buffer leaving any extra bytes in the buffer.

  6. The following user says thank you to ChrisW67 for this useful post:

    Viper666 (15th November 2013)

  7. #5
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Big buffer over TCP Socket

    OK thank you very much this is what i needed to know

Similar Threads

  1. Replies: 2
    Last Post: 22nd May 2011, 21:31
  2. Socket buffer fill
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 31st August 2009, 12:25
  3. QImage buffer
    By rafaelsegundo in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2008, 06:48
  4. double buffer ,x11 only ?
    By deepinlife in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2008, 21:07
  5. Buffer
    By AnithaRagupathy in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2007, 06:26

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
  •  
Qt is a trademark of The Qt Company.