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 set Maximum Segment Size

how to set Maximum Segment Size

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 6 Posters 3.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.
  • mmcmmcM Offline
    mmcmmcM Offline
    mmcmmc
    wrote on last edited by
    #1

    Hi,
    My app communicate with a small embedded device over TCP. I need to limit max data length each packets when i send data.
    Is there any magic setting for QTcpSocket object ?

    By the way i tried QAbstractSocket::SendBufferSizeSocketOption but nothing changed.

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

      Hi,

      How do you do it otherwise ?

      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
      0
      • mmcmmcM Offline
        mmcmmcM Offline
        mmcmmc
        wrote on last edited by
        #3

        Dear @SGaist I did not understand what you meant? Isn't there any solution on QTCPSocket ?

        1 Reply Last reply
        0
        • yuvaramY Offline
          yuvaramY Offline
          yuvaram
          wrote on last edited by
          #4

          Hi @mmcmmc
          this function could help you.
          you can set max limit of write data.

          qint64 QAbstractSocket::writeData(const char * data, qint64 maxSize)

          Yuvaram Aligeti
          Embedded Qt Developer
          : )

          1 Reply Last reply
          0
          • mmcmmcM mmcmmc

            Hi,
            My app communicate with a small embedded device over TCP. I need to limit max data length each packets when i send data.
            Is there any magic setting for QTcpSocket object ?

            By the way i tried QAbstractSocket::SendBufferSizeSocketOption but nothing changed.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @mmcmmc
            Do you call socket->flush() straight after each write?

            I'm thinking that, say, https://git.merproject.org/mer-core/qtbase/commit/6aa22732232f662d0e259f2b92593a457483b842 implies QAbstractSocket::SendBufferSizeSocketOption should do the job, assuming you're trying to use SO_SNDBUF?

            I am unsure about @yuvaram's suggestion, as it says nothing about what the OS might use in its own buffering for packet data length.

            Oh, BTW, are you on MacOS?? Problem reported in http://www.qtcentre.org/archive/index.php/t-66450.html ?

            1 Reply Last reply
            0
            • mmcmmcM Offline
              mmcmmcM Offline
              mmcmmc
              wrote on last edited by
              #6

              Dear @yuvaram ,
              I use this function without problem. My issue is when i send a 250MB stream with writeData function, this try to send all data at one time. But my device accepts 256Byte for each packet.
              One solution is i can split data and send to device packets with a period or after getting device response. But TCP Layer already works this way and i wonder if any setting for this operation solution should be more elegant.

              and dear @JonB yes i tried to call flush() but nothing changed. I'm on Windows and logging traffic with Wireshark.
              or do i use correctly below function ?

              _oTCPSocket.setSocketOption(QAbstractSocket::SendBufferSizeSocketOption,256);
              
              JonBJ 1 Reply Last reply
              0
              • mmcmmcM mmcmmc

                Dear @yuvaram ,
                I use this function without problem. My issue is when i send a 250MB stream with writeData function, this try to send all data at one time. But my device accepts 256Byte for each packet.
                One solution is i can split data and send to device packets with a period or after getting device response. But TCP Layer already works this way and i wonder if any setting for this operation solution should be more elegant.

                and dear @JonB yes i tried to call flush() but nothing changed. I'm on Windows and logging traffic with Wireshark.
                or do i use correctly below function ?

                _oTCPSocket.setSocketOption(QAbstractSocket::SendBufferSizeSocketOption,256);
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @mmcmmc
                I believe your code should be correct for setting SO_SNDBUF. However, I don't think that changes packet size. Sorry, I have to rush, you may need to Google...

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  Im wondering if you are talking about MTU frame size defined by the OS/drivers?
                  https://support.zen.co.uk/kb/Knowledgebase/Changing-the-MTU-size-in-Windows-Vista-7-or-8

                  JonBJ 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Hi
                    Im wondering if you are talking about MTU frame size defined by the OS/drivers?
                    https://support.zen.co.uk/kb/Knowledgebase/Changing-the-MTU-size-in-Windows-Vista-7-or-8

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @mrjj , @mmcmmc

                    If the "MTU" is indeed the same thing, when I had once to play with TCP packet sizes under Windows I had to make a change in the Registry. Trouble is, like your MTU solution, I believe this sets the TCP packet size globally for your machine. I don't know of a way to change it per device....

                    Certianly try @yuvaram's suggestion of reducing how may bytes you pass to writeData(). Trouble is, if they're passed quickly, I think the OS will buffer them into its own packets. Additionally, there may be https://en.wikipedia.org/wiki/Nagle's_algorithm and TCP_NODELAY to worry about....

                    1 Reply Last reply
                    2
                    • Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #10

                      @mmcmmc maybe the problem is on the TCP stack implemented in your "small embedded device". BTW, could it be possible you provide details about it, what OS if any is running, etc. The TCP segment size (MSS, Maximum Segment Size, )is negotiated between the two devices that are establishing a logical connection, see here for a better description.

                      In addition please keep in mind that TCP is not a packet protocol, it is a stream protocol (as described here).

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      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