2016-11-04 33 views
0

我在树莓派上创建了一个小型的C++/c http套接字服务器。在过去,我一次只发送/接收1460个数据字节。尽管最近我已经意识到我可以发送更多的信息。我想尽可能快地从服务器发送数据到客户端。我可以获得客户端可以处理的窗口大小(最大段大小),以便我可以发送该数量的数据。说如果它是8192,那么我想在每个服务器套接字上发送这个数量。任何人都可以给我一些关于如何做到这一点的指示?TCP套接字服务器C++/c窗口大小

+1

只要发送尽可能多的send()'。你不需要知道窗口的大小。 TCP将处理细节。使用一个大的应用程序缓冲区,比如32k或更多。 – EJP

+0

同意@EJP - 客户端请求他们想要接收的缓冲区大小 - 套接字通信决定什么会通过以及何时 – dbmitch

回答

0

使用setsockopt与TCP_MAXSEG:

int mss; 
socklen_t len = sizeof mss; 
getsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &mss, &len); 

man tcp

TCP_MAXSEG 
     The maximum segment size for outgoing TCP packets. In Linux 2.2 
     and earlier, and in Linux 2.6.28 and later, if this option is 
     set before connection establishment, it also changes the MSS 
     value announced to the other end in the initial packet. Values 
     greater than the (eventual) interface MTU have no effect. TCP 
     will also impose its minimum and maximum bounds over the value 
     provided. 

根据this question,这应该后进行建立连接,否则一般缺省值将被返回。

相关问题