Skip to content

Instantly share code, notes, and snippets.

@fjakobs
Created January 5, 2011 12:20
Show Gist options
  • Save fjakobs/766248 to your computer and use it in GitHub Desktop.
Save fjakobs/766248 to your computer and use it in GitHub Desktop.
socket.io xhr-polling bug
<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>
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