简体   繁体   English

如何配置/减少TCP段大小

[英]How to configure/reduce tcp segment size

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). 我需要通过tcp将数据从计算机发送到远程服务器,并且需要对数据进行分段(这是测试)。 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设置MSS

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. 但是,经过更多的搜索之后,似乎可以使用该解决方案告诉服务器我的机器可以接受的TCP分段大小,而不是在我的机器要发送到服务器的tcp数据包/分段上设置分段大小。

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). 我还了解了MTU及其更改方法,但这似乎并不是我想要的,因为我需要/想要在更高级别(传输级别)上分割数据。 My questions are 1) how can I set MSS for TCP segments that my machine is sending? 我的问题是1)如何为我的机器正在发送的TCP段设置MSS? 2) is it possible to do it using Java? 2)是否可以使用Java做到这一点?

Sorry for these newbie questions. 对不起,这些新手问题。

In C you can do this using by setting the TCP_MAXSEG socket option; 在C语言中,您可以通过设置TCP_MAXSEG套接字选项来实现。 see man 7 tcp . man 7 tcp

In Java, the relevant socket option is not exposed in the standard Socket APIs . 在Java中,相关的套接字选项未在标准Socket API中公开。 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. 但是,有在该页面,如果你实现了一个非标准的SocketImpl类,你也许可以设置其它选项的提示。

如果可以的话,只需设置一个小的套接字发送缓冲区大小即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM