Created
April 5, 2011 08:20
-
-
Save 3rd-Eden/903224 to your computer and use it in GitHub Desktop.
Serverside client transport detection for Socket.io
This file contains hidden or 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
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