Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created April 5, 2011 08:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3rd-Eden/903224 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/903224 to your computer and use it in GitHub Desktop.
Serverside client transport detection for Socket.io
require.paths.unshift('/usr/local/lib/node/socket.io/lib/socket.io/transports');
var htmlfile = require('htmlfile')
, flashsocket = require('flashsocket')
, jsonppolling = require('jsonp-polling')
, websocket = require('websocket')
, xhrmultipart = require('xhr-multipart')
, xhrpolling = require('xhr-polling');
var http = require('http')
, io = require('socket.io');
var app = http.createServer(function(req, res){
res.writeHead(200);
res.write('<script type="text/javascript" src="/socket.io/socket.io.js"></script>');
res.write('<script type="text/javascript">var socket = new io.Socket(); socket.connect();</script>');
res.end('<script type="text/javascript">document.write("Connecting using: " + socket.transport.type );</script>');
});
app.listen(8080)
var socket = io.listen(app);
socket.on('connection', function(client){
console.log( "websocket: " + (client instanceof websocket));
console.log( "htmlfile: " + (client instanceof htmlfile));
console.log( "flashsocket: " + (client instanceof flashsocket));
console.log( "jsonppolling: " + (client instanceof jsonppolling));
console.log( "xhrmultipart: " + (client instanceof xhrmultipart));
console.log( "xhrpolling: " + (client instanceof xhrpolling));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment