2016-11-04 39 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,這應該後進行建立連接,否則一般缺省值將被返回。

相關問題