WebSocket cuts off buffers over 528 bytes #81
-
Tried sending more than 528 bytes, ws.onEvent([](AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
(void)len;
if (type == WS_EVT_CONNECT) {
client->setCloseClientOnQueueFull(false);
client->ping();
} else if (type == WS_EVT_DATA) {
AwsFrameInfo *info = (AwsFrameInfo *)arg;
if (info->final && info->index == 0 && info->len == len) {
if (info->opcode == WS_BINARY) {
Serial.println(len); // never more than 528
memcpy(myBuffer, data, len);
}
}
}
}); What could cause this? |
Beta Was this translation helpful? Give feedback.
Answered by
willmmiles
Feb 18, 2025
Replies: 1 comment 9 replies
-
I cannot reproduce with our Websocket example: > base64 -i /dev/urandom | head -c 1024 | websocat ws://192.168.4.1/ws in the serial console:
|
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If one or more of the devices in question is an ESP8266, the LwIP TCP stack defaults to a MSS (maximum segment size) of 536. This means it sends and receives no more than 536 payload bytes per packet. I don't know much about the WebSocket protocol specifically, but add a little framing overhead and 528 is a reasonable maximum payload to expect in a single call.
The
onEvent()
callback is called for every data packet handed up by LwIP. You should be able to tell you've received only partial data via comparinglen
toinfo->len
--info->len
carries the original event size, whilelen
is the number of bytes received in this packet. Iflen < info->len
, you're responsible for doing your own buffe…