Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtcpSocket waitForBytesWritten()
Qt 6.11 is out! See what's new in the release blog

QtcpSocket waitForBytesWritten()

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    great88
    wrote on last edited by
    #1

    What does waitForBytesWritten(-1) do ?

    According to documentation , it returns a bool indicating whether any bytes were successfully written .
    But I notice that it returns false almost all the time even though it seems the data was indeed sent ?

    I am still having a problem though where sometimes , randomly , data doesn't appear to reach some clients of the server . I thought I had dealt with this problem before but it keeps re-appearing . Can this have something to do with running socket code from different threads ? I tried using QTcpSocket::flush() , it seems to help a little but still some clients randomly don't receive .

    Is it OK to spawn new threads within readyRead() handler and write to sockets within that thread ?
    What about referencing and running , within the thread , thread parent functions that write to the sockets . Would that cause problems ? Something tells me it would but would like confirmation .

    1 Reply Last reply
    0
    • C Offline
      C Offline
      compor
      wrote on last edited by
      #2

      hello,

      it depends on the usage and that function helps implement a blocking socket behaviour. this one blocks till the data are transferred to the device i.e. the socket buffer - the actual transmission by the OS net stack is something different.

      as for your threads, i can't really say, as long as you didn't have to subclass QThread, cause that's a no-no technique.

      for your clients randomly not receiving, i would suggest a network capture (e.g. using wireshark) on both ends, server and client.
      if the streams match on a network level, then it might be that the client app just doesn't pick up the data. it might sound far-fetched, but it could happen.

      purposes as understood by the purposer will be misunderstood by others

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved