Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Socket io + static file serving with connect
<!-- This should be served by your server -->
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
var connect = require('connect')
, http = require('http');
var app = connect().use(connect.static(__dirname));
var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
server.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment