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. How to know that a QTcpSocket has no more data comming? [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

How to know that a QTcpSocket has no more data comming? [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.9k 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.
  • B Offline
    B Offline
    billconan
    wrote on last edited by
    #1

    Hello guys,

    I am working on a Qt web framework, mimicking the usage of node.js or golang. And as a side project, I am using it to write a blog program. This project started with this simple Qt http server example I found here:
    http://doc.qt.nokia.com/solutions/4/qtservice/qtservice-example-server.html

    Everything seemed working, I was able to render html, parse the http header, register different path handlers to handle different requests and also serve binary contents to the client, such as QImage.

    However, yesterday, I wanted to implement the image uploader of my blog. And my server cannot work properly. The client side uploader code is from a jquery uploader based on ajax. it uses XMLHttpRequest to send the file. My server can capture the head of the sent file, but it can only be 64kb in size at most. From the Google Chrome developer tool, I can see that the post request is "cancelled". I am not calling socket->close() at the end of the readyRead() slot, but still the post request is cancelled.

    So how should I receive the data from a QTcpSocket? right now, I put everything inside the readyRead() slot, but when there are more than one package, how should I know that all the data has been sent?

    I looked at the lookback example, http://doc.qt.nokia.com/latest/network-loopback.html. but the solution there isn't fit my problem. it knows the size of the sent file in advance and only closes the socket when the received data matches that size.

    There is another thing that I am worried:
    Since the QTcpSocket is asynchronized, will the data come in the order of being sent? No matter how much time I spend to process each chunk of the data? Is there any timeout issues I should care?

    For example, if I process the first chunk of the data for a long time, and before I finish processing it and put it into my temp buffer, the second chunk has come and invoked the readyRead() slot again and I don't spend too much time processing it, which ends up making the second chunk of data appears in front of the first chunk in side my temp buffer. Could this be possible?

    Thank you so much for your answers!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      billconan
      wrote on last edited by
      #2

      After asked a friend, I kinda figured out my problems.

      And I did actually call socket->close accidentally, that explains the cancelled request.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yanbellavance
        wrote on last edited by
        #3

        Can you please edit the title of this question and place [SOLVED] at the beginning.

        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