Created
September 22, 2012 22:49
-
-
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...
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
/* 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); | |
}); | |
}); |
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
/* 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 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
// 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