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 Read Size - Is it possible to grab larger than 8192?
Forum Update on Monday, May 27th 2025

QTcpSocket Read Size - Is it possible to grab larger than 8192?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.3k 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.
  • D Offline
    D Offline
    d_ly56
    wrote on last edited by
    #1

    Hey All,

    Hope everyone is doing well! I am running into an issue that I can't get an answer to on Google. Hopefully, someone can help me and/or point me in the right direction......So, I have a TCP Client/Server deal going on. My server is sending data in larger amounts than the 8192 length that TCP read can handle.

    Code below is just something that I am using to grab the data from the server

    if(this->socket->waitForReadyRead(3000))
        {
            qint64 len = this->socket->bytesAvailable();
            char *data = new char[len];
            // len maxes out at 8192 here
            this->socket->read(data, len);
        }
    

    So, my question is, is there a way to increase the size of the socket read size (i.e double? triple) ? Because as of right now, I am sending in 11,416 but the socket read can only handle 8192.

    Or, is there a way to implement the read to be separated into multiple reads if the data exceeds 8192?
    So, something like this... I'm using pseudocode down here

    if(data->coming in is larger than 8192)
        then read the first 8192, pause, send remaining
    else
        send anything below 8192 regularly
    

    Thank you so much for taking the time to read this post!!!
    Derek

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You will likely be interested in QDataStream transactions to handle that kind of cases.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D Offline
        D Offline
        d_ly56
        wrote on last edited by
        #3

        Hi @SGaist ,

        Thank you for your response! I apologize for mine being extremely late, I was out this previous weekend.

        So, I just finished reading what you proposed with the QDataStream and I am a little bit confused on how to implement this.

        qint64 len = this->socket->bytesAvailable();
        

        len, in this case, will always return 8192, regardless of the size (if it is larger than 8192). Would I need to use the peek function to see how much the server is sending and then implement the QDataStream?

        Also, how would I implement the read function with the QDataStream? Below is what I'm thinking of, and I'm 99% sure that it is not correct...

        if(this->socket->waitForReadyRead(1000)){
            qint64 len = this->socket->bytesAvailable();
            
            // I will try using peek here to get actual size instead of len
            if(len > 8192){
                QDataStream in(&file);
                
                // How do I implement the datastream here with socket read?        
            else{
                char *data = new char[len];
                this->socket->read(data, len);
            }
        

        Thanks so much!!
        Derek

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can see an example of use in the Fortune Client example. The idea is that the read transaction does the handling of "missing data" for you.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • D Offline
            D Offline
            d_ly56
            wrote on last edited by
            #5

            Hi @SGaist ,

            Thanks!!! Alright, that was a big help!! I got it going!

            Thanks again,
            Derek

            1 Reply Last reply
            1

            • Login

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