Skip to content

Instantly share code, notes, and snippets.

@davidrielo
Forked from jchillerup/client.js
Created August 30, 2018 14:09
Show Gist options
  • Save davidrielo/6b5b28431ed06f529a663038012b371c to your computer and use it in GitHub Desktop.
Save davidrielo/6b5b28431ed06f529a663038012b371c to your computer and use it in GitHub Desktop.
remote reloading of web content with socket.io and node
var socket = io.connect('http://HOSTNAME:8080');
socket.on('reload', function (data) {
location.reload();
});
/*
socket.on('eval', function(data) {
eval(data.evalString);
});
*/
var io = require('socket.io').listen(8080);
var http = require('http');
io.sockets.on('connection', function (socket) {
// nothing currently
});
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Reloading clients\n');
io.sockets.emit('reload', {});
}).listen(1337, "HOSTNAME");
console.log('Server running at http://HOSTNAME:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment