Skip to content

Instantly share code, notes, and snippets.

@aashay
Created September 22, 2012 22:49
Show Gist options
  • Save aashay/3768121 to your computer and use it in GitHub Desktop.
Save aashay/3768121 to your computer and use it in GitHub Desktop.
socket.io 0.9.10 + socket.io-client 0.9.10 are not playing nice with xhr-polling...
/* 1. node server.js */
var io = require('socket.io').listen(1234);
io.configure(function () {
io.set('transports', ['xhr-polling']);
});
io.set('authorization', function(handshakeData, ack) {
return ack(null, true);
});
io.sockets.on('connection', function (socket) {
console.log("Someone connected!");
socket.on("news", function(data){
console.log(data);
});
});
/* 2. node client.js */
var io = require('socket.io-client');
var socket = io.connect('http://localhost:1234');
socket.on("error", function(err){
console.log(err);
});
socket.on('connect', function(message){
console.log("Connection established!"); //You'll never see this.
socket.emit("news", "hi");
});
// This is the error you'll see after several seconds.
timers.js:103
if (!process.listeners('uncaughtException').length) throw e;
^
TypeError: Cannot call method 'onClose' of null
at Object._onTimeout (/private/tmp/sockettest/node_modules/socket.io-client/lib/socket.js:281:22)
at Timer.list.ontimeout (timers.js:101:19)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment