Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Disconnect on large websocket message #21

@Jonty

Description

@Jonty

Hello!

I'm trying to use this library on an ESP32 against API's that stream very large messages (~40k).

It works fine for the smaller messages, however as soon as a large message (should be) received a WebsocketsEvent::ConnectionClosed event is emitted and the connection is dropped.

I did some brief digging and it looks like the TCP connection stops being available(), but I'm not clear why.

This example code demonstrates the problem:

#include <ArduinoWebsockets.h>
#include <WiFi.h>

const char* ssid = "SSID";
const char* password = "PASSWORD";

const char* websockets_connection_string = "wss://ws.blockchain.info/inv";

using namespace websockets;

void onMessageCallback(WebsocketsMessage message) {
    Serial.print("Got Message: ");
    Serial.println(message.data());
}

WebsocketsClient client;

void onEventsCallback(WebsocketsEvent event, String data) {
    if(event == WebsocketsEvent::ConnectionOpened) {
        Serial.println("ConnectionOpened");
    } else if(event == WebsocketsEvent::ConnectionClosed) {
        Serial.println("ConnectionClosed");
    } else if(event == WebsocketsEvent::GotPong) {
        Serial.println("GotPong");
    }
}

void setup() {
    Serial.begin(115200);

    WiFi.begin(ssid, password);
    for(int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
        Serial.print(".");
        delay(1000);
    }

    client.onMessage(onMessageCallback);
    client.onEvent(onEventsCallback);

    client.setCACert(nullptr);
    client.connect(websockets_connection_string);

    // Works - results in "GotPong"
    client.ping();

    // Works - results in "Got Message: {"op":"pong"}"
    client.send("{\"op\":\"ping\"}");

    // FAILS - results in "ConnectionClosed"
    // This will cause ~40k of data to be returned down the websocket
    client.send("{\"op\":\"ping_block\"}");
}

void loop() {
    client.poll();
}

Any help very much appreciated.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingresolvedthe issue was resolved

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions