Skip to content

Reconnect websocket after server restarts? #110

@mshulman

Description

@mshulman

I'm not sure how this is supposed to work. My code works as long as the server is up before the client attempt to connect. But if the server restarts or otherwise faults, I don't know how to make the code reconnect.

Here's what I'm doing

void setUpSubscription() {
    Serial.println("Setting up subscription");
    client.begin("/signalk/v1/stream?subscribe=none");
  
    while (!client.connected()) {
      delay(100);
      ; // wait to connect
    }
}

void loop() {
  setUpSubscription();
  while (client.connected()) {
     // do stuff
  }
  Serial.println("client disconnected");
}

The problem is that the client.begin() doesn't work on a disconnected socket (I think).

What's the right thing to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions