Created
January 5, 2011 12:20
-
-
Save fjakobs/766248 to your computer and use it in GitHub Desktop.
socket.io xhr-polling bug
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
<html> | |
<head> | |
<script src="socket.io.js"></script> | |
<script> | |
var logDiv; | |
function test() { | |
var socket = new io.Socket(null, { | |
rememberTransport : false, | |
transports : [ 'xhr-polling' ], | |
transportOptions : { | |
"xhr-polling": { | |
timeout: 30000 | |
}, | |
"jsonp-polling": { | |
timeout: 30000 | |
} | |
} | |
}); | |
var message = "Dit is een test"; | |
logDiv = document.getElementById("testLog"); | |
for (var i = 0; i < 10; ++i) | |
message = message.concat(message); | |
socket.on("connect", function () { | |
logMe("Server connect"); | |
socket.send(message); | |
}); | |
socket.on("disconnect", function () { | |
logMe("Server disconnect"); | |
}); | |
socket.on("message", function (data) { | |
logMe("Server message " + data.length); | |
socket.send(data); | |
}); | |
socket.connect(); | |
} | |
function logMe(txt) { | |
logDiv.appendChild(document.createTextNode(txt)); | |
logDiv.appendChild(document.createElement("br")); | |
} | |
</script> | |
</head> | |
<body onload="test()"> | |
<div id="testLog" /> | |
</body> | |
</html> |
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
var fs = require("fs"), | |
http = require("http"), | |
io = require("../../../support/cloud9/support/socket.io"); | |
var server = http.createServer(function(req, res) { | |
res.writeHead(200, { | |
"Content-Type": "text/html" | |
}); | |
res.end(fs.readFileSync(__dirname + ((req.url.indexOf("socket.io.js") > -1) ? "/socket.io.js" : "/SocketIOTest.html")).toString()); | |
}); | |
server.listen(4000); | |
var socket = io.listen(server); | |
socket.on("connection", function (client) { | |
console.log("Client connection"); | |
client.on("disconnect", function () { | |
console.log("Client disconnect"); | |
}); | |
client.on("message", function (data) { | |
console.log("Client message"); | |
// setTimeout(function () { | |
client.send(data); | |
// }, 1000); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment