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

auto reconnect websocket on close event #43

Merged
merged 1 commit into from
Jan 10, 2018
Merged

auto reconnect websocket on close event #43

merged 1 commit into from
Jan 10, 2018

Conversation

thunderace
Copy link
Contributor

It's a workaround for unexpected websocket close.

@omersiar
Copy link
Collaborator

I believe close event is triggered when the Browser's window is actually closed. I rarely witnessed Websocket is closing abnormaly. Did you investigate further? Why is your websocket comm is failing?

@omersiar omersiar merged commit 3ff7101 into esprfid:master Jan 10, 2018
@omersiar
Copy link
Collaborator

omersiar commented Jan 10, 2018

Simple ping-pong can be implemented.

Client side:

function ping() {
	websock.send("{\"type\":\"ping\"}");
}

var ping = setInterval(ping, 10000);

if (json.type === "pong") {
	console.log("Server is alive.");
}

Server side:

if (obj.type === "ping") {
        console.log("Got ping from client.");
	var pong = {type: "pong"};
	wss.broadcast(pong);
}

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

Successfully merging this pull request may close these issues.

None yet

2 participants