Created
September 15, 2011 21:58
-
-
Save kurtraschke/1220609 to your computer and use it in GitHub Desktop.
Demonstration of polling disconnect in socket.io
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/socket.io.js"></script> | |
<script> | |
var connectTime; | |
var socket = io.connect('/', {transports: ['websocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling']}); | |
socket.on('connect', function(){ | |
console.log('connected'); | |
connectTime = new Date().getTime(); | |
console.log(connectTime); | |
}); | |
socket.on('disconnect', function(){ | |
console.log('disconnected'); | |
var disconnectTime = new Date().getTime(); | |
console.log(disconnectTime); | |
console.log(disconnectTime-connectTime); | |
}); | |
</script> | |
</head> | |
<body> | |
</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 httpProxy = require('http-proxy'); | |
var express = require('express'); | |
var io = require('socket.io'); | |
httpProxy.createServer(8000, 'localhost').listen(9000); | |
var app = express.createServer(); | |
app.configure(function() { | |
app.use(express.static(__dirname)); | |
}); | |
io = io.listen(app); | |
//uncomment to force jsonp-polling | |
//io.configure(function(){io.set('transports', ['jsonp-polling']);}); | |
app.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This test mimics conditions on Joyent's no.de, where the use of node-http-proxy prevents WebSockets from working (due to http-party/node-http-proxy#97). Fallback to xhr-multipart doesn't work either; it's not clear if socket.io still supports xhr-multipart, but even if it does, node-http-proxy can't proxy it: http-party/node-http-proxy#70.
As a result, socket.io falls back to xhr-polling; as the test demonstrates, the connection reliably fails after 135 seconds. Switching to jsonp-polling gives the same results.