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

handle disconnect from server #28

Open
olmedocr opened this issue Feb 23, 2017 · 11 comments
Open

handle disconnect from server #28

olmedocr opened this issue Feb 23, 2017 · 11 comments

Comments

@olmedocr
Copy link

Hi, is there a way in the js library of handling a disconnect from the blynk server or checking the connection status in order to retry the connection if failed?
Thanks

@jsjones80
Copy link

has there been any change on this? currently when an internet loss happens the script has no idea to reconnect.

thanks

@reluxa
Copy link

reluxa commented Nov 10, 2017

Is there any update on this?

@gablau
Copy link

gablau commented Apr 28, 2018

on blynk.js coment line 592: this.emit('error', err.code?err.code:'ERROR');

Blynk.prototype.error = function(err) {
  var self = this;
  //if we throw error and user doesn't handle it, app crashes. is it worth it?
  //this.emit('error', err.code?err.code:'ERROR'); //comment and nodejs not crash on connection error
  console.error('Error', err.code);
  //starting reconnect procedure if not already in connecting loop
  if(!self.timerConn) {
    setTimeout(function () {self.connect()}, 5000);
  }
};

Nodejs not crash on connection error, and try to reconnect!!

@tuloski
Copy link
Contributor

tuloski commented Nov 1, 2018

It's not working very well. It continuously try to reconnect and disconnect in an infinite loop.

@guymcswain
Copy link

If the blynk server is unavailable for some reason, you can observe the error message and choose to disconnect if you wish. The intent of the loop is to keep trying to connect, for example, in the case of temporary network drop out.

@tuloski
Copy link
Contributor

tuloski commented Nov 2, 2018

What I meant for loop, is that when it disconnects, it tries to reconnect but somehow it also try to disconnect in a continuous loop where it reconnects and immediately disconnect and so on forever.
I tried to debug a bit but I wasn't able to find the failure point.
To reproduce just disconnect internet and reconnect internet.

@guymcswain
Copy link

guymcswain commented Nov 3, 2018

I'm currently on local blynk server.

I pulled the network cable to blynk server then looked at my hw client console and see no change. Also on UI, no change. (Likely tcp maintaining session during timeout period)

Reconnect network cable then touched the UI connection status icon. A warning message was momentarily displayed (too fast for me to read and remember). Back on my hw client console, I now see two error messages: one is ECONNRESET, the other is 'undefined'. I also received two 'connect' events but no 'disconnect' event.

My app is working but I now have three connect handlers running because I expected to receive disconnect before another connect. This is a blynk library bug but I can easily work around it by using a 'once' connect handler.

In short, I didn't see the same problem you are experiencing. Did you pull the network connection from the host running your hw client? I can't easily do that since mine is wireless.

@tuloski
Copy link
Contributor

tuloski commented Nov 3, 2018

I pulled the network cable from the host running this library (my "hardware").

Aren't the three connect handlers making some mess, like trying to disconnect and so on?

@guymcswain
Copy link

Ok, just ran the same experiment on my host running blynk-library-js. Got these messages:

Disconnect blynk
2018.11.03 1:47 pm - warn: Received disconnect from Blynk server
REARMING DISCONNECT
Connecting to TCP: 10.0.100.7 8080
Connected
Authorized

Which seems to work as expected. What version of the blynk library are you using - installed from npm or git repo?

@tuloski
Copy link
Contributor

tuloski commented Nov 3, 2018

From repo, latest commit (but it was the same 10-15 commits ago). I'm using public server.

@bestpika
Copy link

bestpika commented Jan 23, 2019

process.on('uncaughtException', err => {
  console.log(err)
})

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

7 participants