-
-
Save MrAndrewMal/584b75d8ab0c6193fc74845313c366ab to your computer and use it in GitHub Desktop.
remote reloading of web content with socket.io and node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socket = io.connect('http://HOSTNAME:8080'); | |
socket.on('reload', function (data) { | |
location.reload(); | |
}); | |
/* | |
socket.on('eval', function(data) { | |
eval(data.evalString); | |
}); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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