Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<script src="socket.io/socket.io.js"></script>
<script>
var heartbeatInterval;
var heartbeatCount = 0;
var socket = io.connect('http://192.168.0.110:8088');
socket.on('connect', function connectFn(data) {
console.log('connected');
var heartbeat = function heartbeatFn()
{
console.log('sending heartbeat ' + heartbeatCount);
socket.emit('heartbeat', heartbeatCount);
heartbeatCount += 1;
};
clearInterval(heartbeatInterval);
heartbeatInterval = setInterval(heartbeat, 1000);
});
socket.on('reconnect', function disconnectFn(data) {
console.log('reconnected');
});
socket.on('disconnect', function disconnectFn(data) {
console.log('disconnected');
clearInterval(heartbeatInterval);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment