Results 1 to 2 of 2

Thread: QTcpSocket emitting readyRead() sync

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QTcpSocket emitting readyRead() sync

    Hello!

    I have an debug application with a QTcpSocket client that should receive something like 6 packages by second - that's precise. So I would imagine that the readyRead() signal would be emmited around 6 times per second, each time related to one of the packages that were send. But what happens is very different:

    rather than emiting 6 singals per second well divided in time, usually 2 to 3 readyRead signals are emmited very quickly one after the other with the data received:

    Qt Code:
    1. "0" "56:10:484" 8192 Data received (readyRead)
    2. "0" "56:10:485" 323 Data received (readyRead)
    3. "0" "56:11:358" 8192 Data received (readyRead)
    4. "0" "56:11:358" 323 Data received (readyRead)
    5. "0" "56:12:340" 3472 Data received (readyRead)
    6. "0" "56:12:340" 5043 Data received (readyRead)
    7. "0" "56:13:542" 3472 Data received (readyRead)
    8. "0" "56:13:542" 5043 Data received (readyRead)
    9. "0" "56:14:306" 8192 Data received (readyRead)
    10. "0" "56:14:306" 323 Data received (readyRead)
    11. "0" "56:15:397" 3472 Data received (readyRead)
    12. "0" "56:15:398" 5043 Data received (readyRead)
    To copy to clipboard, switch view to plain text mode 

    (the number before "Data received" is get by bytesAvailable())

    And that happens, as you may see, like once per second. Is there a way to change this behaviour making readyRead() be emitted in a way closer to what was expected? It's like if there was a thread inside QIODevice that looks for new data once per second...


    Thanks,

    Momergil

    Obs.: maybe has something to do with [http://www.qtcentre.org/threads/1502...d(QTCPSOCKET)]

  2. #2
    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: QTcpSocket emitting readyRead() sync

    Is there a way to change this behaviour making readyRead() be emitted in a way closer to what was expected?
    Qt is issuing readyRead() exactly as expected and documented. readRead() is signalled when new data has arrived. You need to understand that there is no relationship between the size and timing of data blocks written by the sender and the size and timing of received chunks of data (driven by network block, hardware and operating system buffers sizes). TCP guarantees that all data written will arrive intact and in the correct order; it does this using a system of sequence numbers, checksums, acknowledgement messages, and retransmissions. TCP makes no guarantees about timing (it cannot control network conditions) or that a chunk written at one end is received as a single chunk at the other (this is, BTW, unlikely except for small infrequent chunks).

    If you want to emit a signal only when some complete application layer protocol data unit (PDU) is received then you need to buffer the incoming data, inspect the data for a complete PDU, and emit the signal you want.

    Depending on the application, UDP may be a better choice.

Similar Threads

  1. QTcpSocket waitForReadyRead() not re-emitting signal
    By alitoh in forum Qt Programming
    Replies: 3
    Last Post: 2nd November 2012, 12:29
  2. QTcpSocket readyRead strange behavior
    By naroin in forum Qt Programming
    Replies: 46
    Last Post: 21st January 2011, 22:28
  3. QTcpSocket and readyRead and QTimer
    By cafu in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2009, 13:36
  4. Question in readyRead(QTCPSOCKET)
    By morgana in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2008, 18:11
  5. QTcpSocket readyRead and buffer size
    By pdoria in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2008, 10:11

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.