Created
January 31, 2013 13:48
-
-
Save egm0121/4682989 to your computer and use it in GitHub Desktop.
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
<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> | |
Ciao, sono un piccolo socket.io |
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 app = require('http').createServer(handler) | |
, io = require('socket.io').listen(app) | |
, fs = require('fs') | |
app.listen(81); | |
function handler (req, res) { | |
fs.readFile(__dirname + '/index.html', | |
function (err, data) { | |
if (err) { | |
res.writeHead(500); | |
return res.end('Error loading index.html'); | |
} | |
res.writeHead(200); | |
res.end(data); | |
}); | |
} | |
io.sockets.on('connection', function (socket) { | |
socket.emit('news', { hello: 'world' }); | |
socket.on('bo', function (data) { | |
socket.broadcast.emit('news', data ); | |
socket.emit('news', data ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment