исправляем библиотеку сокетов для работы с фреймами

This commit is contained in:
Dmitry Borisenko
2022-10-08 00:28:45 +02:00
parent 6e0392ac03
commit 645e90379c
3 changed files with 20 additions and 8 deletions

View File

@@ -225,13 +225,17 @@ bool WebSocketsServerCore::broadcastTXT(String & payload) {
* @param headerToPayload bool (see sendFrame for more details)
* @return true if ok
*/
bool WebSocketsServerCore::sendBIN(uint8_t num, uint8_t * payload, size_t length, bool fin, bool headerToPayload) {
bool WebSocketsServerCore::sendBIN(uint8_t num, uint8_t * payload, size_t length, bool fin, bool continuation, bool headerToPayload) {
if(num >= WEBSOCKETS_SERVER_CLIENT_MAX) {
return false;
}
WSclient_t * client = &_clients[num];
if(clientIsConnected(client)) {
return sendFrame(client, WSop_binary, payload, length, fin, headerToPayload);
if(continuation) {
return sendFrame(client, WSop_continuation, payload, length, fin, headerToPayload);
} else {
return sendFrame(client, WSop_binary, payload, length, fin, headerToPayload);
}
}
return false;
}

View File

@@ -65,7 +65,7 @@ class WebSocketsServerCore : protected WebSockets {
bool broadcastTXT(const char * payload, size_t length = 0);
bool broadcastTXT(String & payload);
bool sendBIN(uint8_t num, uint8_t * payload, size_t length, bool fin = true, bool headerToPayload = false);
bool sendBIN(uint8_t num, uint8_t * payload, size_t length, bool fin = true, bool continuation = false, bool headerToPayload = false);
bool sendBIN(uint8_t num, const uint8_t * payload, size_t length);
bool broadcastBIN(uint8_t * payload, size_t length, bool fin = true, bool headerToPayload = false);

View File

@@ -433,15 +433,23 @@ void sendBlobToWsStrHeader(const String& filename, const String& header, uint8_t
size_t payloadSize = file.read(payloadBuf, maxPayloadSize);
if (payloadSize) {
size_t size = headerSize + payloadSize;
bool fin = false;
if (i == 16) {
fin = true;
} else {
if (size == frameSize) {
fin = false;
} else {
fin = true;
}
SerialPrint("I", "FS", String(size) + " " + String(fin) + " " + String(i));
standWebSocket.sendBIN(client_id, frameBuf, size, fin);
bool continuation = false;
if (i == 0) {
continuation = false;
} else {
continuation = true;
}
SerialPrint("I", "FS", String(i) + ") sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
standWebSocket.sendBIN(client_id, frameBuf, size, fin, continuation);
}
i++;
}