1var io = require('socket.io').listen(80); // initiate socket.io server
2
3io.sockets.on('connection', function (socket) {
4 socket.emit('news', { hello: 'world' }); // Send data to client
5
6 // wait for the event raised by the client
7 socket.on('my other event', function (data) {
8 console.log(data);
9 });
10});
11
1<script src="/socket.io/socket.io.js"></script>
2<script>
3 var socket = io.connect('http://localhost'); // connec to server
4 socket.on('news', function (data) { // listen to news event raised by the server
5 console.log(data);
6 socket.emit('my other event', { my: 'data' }); // raise an event on the server
7 });
8</script>
9