Unsolved how to set Maximum Segment Size
-
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.
-
Hi,
How do you do it otherwise ?
-
Dear @SGaist I did not understand what you meant? Isn't there any solution on QTCPSocket ?
-
Hi @mmcmmc
this function could help you.
you can set max limit of write data.qint64 QAbstractSocket::writeData(const char * data, qint64 maxSize)
-
@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 useSO_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 ?
-
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);
-
@mmcmmc
I believe your code should be correct for settingSO_SNDBUF
. However, I don't think that changes packet size. Sorry, I have to rush, you may need to Google... -
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 -
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 andTCP_NODELAY
to worry about.... -
@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).