Skip to content

Instantly share code, notes, and snippets.

@neino3
Created October 19, 2012 06:15
Show Gist options
  • Save neino3/3916481 to your computer and use it in GitHub Desktop.
Save neino3/3916481 to your computer and use it in GitHub Desktop.
fail to connect socket.io server by using htmlfile transport on IE8. contents(HTML) is served from other server.

motivation

I want to connect to socket.io server by using htmlfile transport from contents which served from other contents server (simple http server) on IE8, but fail.

This is verification code. There is two servers. one is socket.io server and another is a contents server which serves index.html. I specify transport as 'htmlfile' in index.html. If you open http://localhost:8888 in IE8, browser tried to connect to socket.io server. Handshake is done successfully, but after that client does not start transport negotiation of 'htmlfile'.

here is console logs

   info  - socket.io started
socket.io server listening on 7777....
   debug - served static content /socket.io.js
   debug - client authorized
   info  - handshake authorized H5138B0mQDjkKX6_lRG8
var app = require('http').createServer(handler)
, util = require('util')
, fs = require('fs');
app.listen(8888);
console.log('contents server listening on 8888....');
function handler (req, res) {
fs.readFile('index.html', function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>verification htmlfile-transport on IE8</title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="http://localhost:7777/socket.io/socket.io.js"></script>
<script type="text/javascript">
$(function() {
$('#ua').text(navigator.userAgent);
io.transports = ['htmlfile'];
var socket = io.connect('http://localhost:7777');
socket.on('connect',function() {
$('#status').append('::connect::');
$('#transport').append(socket.socket.transport.name);
});
socket.on('connecting',function() {
$('#status').append('::connecting::');
});
socket.on('connect_failed',function(reason) {
$('#status').append('::connect_failed::'+reason);
});
socket.on('reconnect_failed',function() {
$('#status').append('::reconnect_failed::');
});
socket.on('reconnect',function() {
$('#status').append('::reconnect::');
});
socket.on('reconnecting',function() {
$('#status').append('::reconnecting::');
});
socket.on('disconnect', function (reason) {
$('#status').append('->disconnect('+reason+')');
});
socket.on('error', function (reason) {
$('#status').append('->error:'+reason);
});
});
</script>
<h1>Status</h1>
<div id="status"></div>
<h1>Transport</h1>
<div id="transport"></div>
<h1>UA</h1>
<div id="ua"></div>
</body>
</html>
{
"name": "verification-socket.io-htmlfile"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"socket.io": "0.9.10"
}
}
var app = require('http').createServer()
, io = require('socket.io').listen(app)
, util = require('util')
, fs = require('fs');
app.listen(7777);
console.log('socket.io server listening on 7777....');
io.sockets.on('connection', function (socket) {
console.log('connected to socket.io server');
socket.on('disconnect', function () {
console.log('disconnected');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment