How to configure/reduce tcp segment size

2.1k Views Asked by At

I need to send data from my machine to a remote server over tcp and I need the data to be fragmented (it's a test). That explains the reason I am looking for a way to change the segment size to a small number.

I have googled around and I found that we can set MSS using iptables

iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss some-number

However, after more googling, it seems like that solution is used to tell the server the TCP segment size that my machine can accept versus setting the segment size on the tcp packets/segments that my machine is sending over to the server.

I also learnt about MTU and how to change it, but that doesn't seem to be what I want because I need/want to cut my data up in a higher level (in the transport level). My questions are 1) how can I set MSS for TCP segments that my machine is sending? 2) is it possible to do it using Java?

Sorry for these newbie questions.

2

There are 2 best solutions below

0
On

In C you can do this using by setting the TCP_MAXSEG socket option; see man 7 tcp.

In Java, the relevant socket option is not exposed in the standard Socket APIs. However there is a hint in that page that you might be able to set other options if you implemented a non-standard SocketImpl class.

0
On

Just set a small socket send buffer size, if you can.