Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect websocket after server restarts? #110

Open
mshulman opened this issue Jul 25, 2021 · 3 comments
Open

Reconnect websocket after server restarts? #110

mshulman opened this issue Jul 25, 2021 · 3 comments

Comments

@mshulman
Copy link

mshulman commented Jul 25, 2021

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?

mshulman added a commit to mshulman/signalK-fusion-volume that referenced this issue Jul 25, 2021
@ddaydd
Copy link

ddaydd commented Jul 26, 2021

have you implemented a Ping / Pong request ? maybe it could help you.

@mshulman
Copy link
Author

mshulman commented Jul 26, 2021

ddaydd-

Is this something that is implemented on the server? If so, how would I know if the server I’m connecting to implements this?

@ddaydd
Copy link

ddaydd commented Jul 26, 2021

you have to implement it on the server and the client too. maybe this post can help you
https://stackoverflow.com/a/50876880/2979191

what language is your server written in? my server is Meteor which already has ping pong logic ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants