On Github controlz / Presentation-Socket.IO
By Michael Mottola
npm install socket.io
var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); });
<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 app = require('express')() , server = require('http').createServer(app) , io = require('socket.io').listen(server); server.listen(80); app.get('/', function (req, res) { res.render('home'); }); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); });
var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.broadcast.emit('user connected'); });
var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { var tweets = setInterval(function () { getFancyTweet(function (tweet) { socket.volatile.emit('fancy tweet', tweet); }); }, 100); socket.on('disconnect', function () { clearInterval(tweets); }); });