Created
January 5, 2012 20:22
-
-
Save stash/1567083 to your computer and use it in GitHub Desktop.
socket.io transport tracing
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
| 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); | |
| }); | |
| }); |
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
| <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