QtcpSocket waitForBytesWritten()



  • 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 .



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.