I also (like Derrish) wanted to use express to simplify my work ( AWESOME :) ). You can download and extract this sample from http://dl.dropbox.com/u/314941/socketio.zip . I believe that you do not even need to install these modules, because I linked them locally ( just run ) thanks to npm :).
How to install:
alfred@alfred-laptop :~/tmp/socketio$ uname -a Linux alfred-laptop 2.6.35-28-generic
The code:
app.js:
// npm install express // npm install socket.io var sys = require('sys'), express = require('express'), app = express.createServer('127.0.0.1'), io = require('socket.io'); app.use(express.static(__dirname + '/public')); app.get('/', function (req, res) { res.send('Hello World'); }); app.listen(3000); var socket = io.listen(app); socket.on('connection', function (client){ // new client is here! setTimeout(function () { client.send('Waited two seconds!'); }, 2000); client.on('message', function () { }) ; client.on('disconnect', function () { }); });
public /index.html
<html> <p id="text">socket.io</p> <script src="socket.io/socket.io.js"></script> <script src="jquery-1.6.1.min.js"></script> <script> $(document).ready(function(){ var socket = new io.Socket(), text = $('#text'); socket.connect(); socket.on('connect', function () { text.html('connected'); }); socket.on('message', function (msg) { text.html(msg); }); socket.on('disconnect', function () { text.html('disconnected'); }); }); </script>
List of my modules:
alfred@alfred-laptop :~/tmp/socketio$ npm ls /home/alfred/tmp/socketio ├─┬ express@2.3.11 │ ├── connect@1.4.6 │ ├── mime@1.2.2 │ └── qs@0.1.0 └── socket.io@0.6.18
Installed modules (NOT required):
npm install express npm install socket.io
The browser will display:
socket.io , but you probably won't see this because it will be replaced by connected .connected when the user connects to socket.io.- After 2 seconds,
Waited two seconds! displayed Waited two seconds! 
Alfred
source share