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. [Solved ] Checking that the client at the other end is retrieving the data when using QTcpSocket
QtWS25 Last Chance

[Solved ] Checking that the client at the other end is retrieving the data when using QTcpSocket

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.4k Views
  • 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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #1

    The application is an application based on QTcpServer and QTcpSocket. An external application is connecting to the server and requesting data. When the connection is established the server (my application) is sending the data continuously. The client will typically retrieve the information continuously.

    However, there is an external client application which may be stop the retrieval on demand. Also on demand it will "continue" the retrieval of information. However, it basically sends another reconnect. This triggers a new socket in my application. If the stop and start sequence is repeated, each time a new socket will be added. To each of these sockets my application can write without detecting a problem. The write returns the number of bytes written and also error() does not show a problem. state() returns 3 for connected state. No indication that something has changed.

    Has anybody an idea what to check in order to find out that the client is not reading the data?

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

      QTcpSocket::write writes the data into a buffer which is not limited in size. To know when the data is actually sent, you can use the bytesWritten(int) signal.

      For example, you could start a timer each time you call write, and stop it when that signal is received, if the timer times out, it means the client isn't reading from the socket anymore.
      There can be some delay, because both the operating system and the application may be using buffers (and if the client is also using QTcpSocket, you should either explicitly set a read buffer size or open the socket with the flag QIODevice::Unbuffered because the default settings doesn't limit the size of the receive buffer).

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        If the client is not closing the original connection then there's no indication to the server that the client does not want to receive more information on the connection. Sounds like you have a faulty client.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          [quote author="alexisdm" date="1353974018"]QTcpSocket::write writes the data into a buffer which is not limited in size. To know when the data is actually sent, you can use the bytesWritten(int) signal.
          [/quote]

          Thanks alot this helped.
          There are still bytes written for a while. This might be around 20k. Since the amount per second is relatively small (<1k/sec) it takes some time. I guess this might be certainly dependent on OS.
          I am using now a counter for the number of bytes indicated by bytesWritten signal. When this number does not increase anymore also the method bytesToWrite of QTcpSocket shows an increasing number.

          A bit patience missing on my side would have solved it already :-)

          [quote author="ChrisW67" date="1353998233"]If the client is not closing the original connection then there's no indication to the server that the client does not want to receive more information on the connection. Sounds like you have a faulty client.[/quote]
          That reflects my opinion, but it is arguable. Unfortunately, this is one application. The question is how many are around doing the same thing.
          My guess is that a different lib is used. With Qt I could not reproduce.

          Vote the answer(s) that helped you to solve your issue(s)

          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