ESP8266 TCP数据包碎片

发布于 2025-02-04 03:34:43 字数 816 浏览 5 评论 0原文

我正在尝试使用WEMOS D1 MINI PRO(ESP8266)将TCP数据包发送到远程服务器,该Pro(ESP8266)在 lwip v2 high band bandwidth mode(tcp_mss = 1460lwip_功能= 1 )。

我将最大缓冲区大小设置为1810字节:

#define MAX_BUFFER_SIZE 1810

我将缓冲区声明为全局静态变量:

static uint8_t buffer[MAX_BUFFER_SIZE];

并且我使用tcp_write不断地发送packetsize(用户定义的大小)数据包:

uint16_t sent = TCP.write((uint8_t*)buffer,packetSize);

大多数时间我得到<代码>已发送等于Packetsize,但是,一次函数返回较小的值。例如,如果Packetsize = 1135,则我通常会得到第一个不良值等于650和几个零值。发送几次失败后,正常操作会恢复。

我正在寻找这个分裂问题的原因。

思想:无论packetsize是否实际上小于tcp_mss,我是否应该使用缓冲区大小(当前1860)小于TCP_MSS = 1460?如果是,我是否应该尝试将缓冲区作为动态数组,大小等于packetsize

I am trying to send TCP packets to a remote server, using the Wemos D1 Mini Pro (ESP8266), configured in lwIP v2 high bandwidth mode (TCP_MSS = 1460, LWIP_ FEATURES = 1).

I set a maximum buffer size of 1810 bytes :

#define MAX_BUFFER_SIZE 1810

I declare the buffer as a global static variable :

static uint8_t buffer[MAX_BUFFER_SIZE];

and I am continually sending packetSize (user-definable size) packets using TCP_write :

uint16_t sent = TCP.write((uint8_t*)buffer,packetSize);

most of the times I get sent equal to packetSize, however, once a while the function returns a smaller value. For instance, if packetSize = 1135, I usually get the first bad value equal to 650 and a few zero values after that. Normal operation restores after a few failed sends.

I am looking for the reasons behind this fragmentation issue.

Thoughts : should I use a buffer size (currently 1860) smaller than TCP_MSS = 1460, no matter if packetSize is actually smaller than TCP_MSS ? If yes, should I try to declare buffer as a dynamic array with size equal to packetSize ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文