【问题标题】:TCP socket server c++/c window sizeTCP 套接字服务器 c++/c 窗口大小
【发布时间】:2017-03-17 21:41:30
【问题描述】:

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

【问题讨论】:

  • 在每个send() 上发送尽可能多的内容。您不需要知道窗口大小。 TCP 会处理细节。使用较大的应用程序缓冲区,例如 32k 或更多。
  • 同意@EJP - 客户端请求他们想要接收的缓冲区大小 - 套接字通信决定传递什么以及何时传递

标签: c++ c http tcp raspbian


【解决方案1】:

将 getsockopt 与 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,这应该在连接建立之后完成,否则将返回一个通用的默认值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多