Skip to content

Instantly share code, notes, and snippets.

@stash
Created January 5, 2012 20:22
Show Gist options
  • Select an option

  • Save stash/1567083 to your computer and use it in GitHub Desktop.

Select an option

Save stash/1567083 to your computer and use it in GitHub Desktop.
socket.io transport tracing
process.env['NODE_ENV'] = 'production';
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(80);
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.configure('production', function() {
console.log('prod!');
io.set('transports', ['websocket', 'flashsocket', 'xhr-polling', 'jsonp-polling']);
io.set('log level', 1);
});
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("your_host_here");
socket.on('news', function (data) {
socket.emit('my other event', { ua: window.navigator.userAgent, transport: socket.socket.transport.name });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment