Transport d'interrogation d'une erreur de Socket.Io

J'obtiens une erreur de transport lors de l'utilisation de socket.io v1.3.2. C'est juste censé être un test pour la socket.io afin que je puisse me familiariser avec elle.

J'ai un fichier app.js (prises directement à partir de la prise.io docs):

var app = require('http').createServer(handler);
var io = require('socket.io')(app);
var fs = require('fs');

app.listen(3000);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
});

Et un fichier index.html:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <link rel="stylesheet" href="">
</head>
<body>
    <h1>Socket Test</h1>
    <script src="/socket.io/socket.io.js"></script>
    <script>
        var socket = io.connect('http://localhost');
        socket.on('news', function (data) {
            console.log(data);
        });
    </script>

</body>
</html>

Dans la console, j'obtiens l'erreur suivante:

GET http://localhost/socket.io/?EIO=3&transport=polling&t=1422782880286-40 
(index):1 XMLHttpRequest cannot load http://localhost/socket.io/?EIO=3&transport=polling&t=1422782880286-40. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 404.
socket.io.js:3715 engine.io-client:socket socket error {"type":"TransportError","description":0} +37ms
socket.io.js:1402 socket.io-client:manager connect_error +38ms
socket.io.js:1402 socket.io-client:manager reconnect attempt error +1ms
socket.io.js:1402 socket.io-client:manager will wait 5000ms before reconnect attempt +0ms
socket.io.js:3715 engine.io-client:socket socket close with reason: "transport error" +2ms
socket.io.js:3715 engine.io-client:polling transport not open - deferring close +1ms
socket.io.js:1402 socket.io-client:manager attempting reconnect +5s
socket.io.js:1402 socket.io-client:manager readyState closed +0ms
socket.io.js:1402 socket.io-client:manager opening http://localhost +0ms
socket.io.js:3715 engine.io-client:socket creating transport "polling" +5s
socket.io.js:3715 engine.io-client:polling polling +0ms
socket.io.js:3715 engine.io-client:polling-xhr xhr poll +0ms
socket.io.js:3715 engine.io-client:polling-xhr xhr open GET: http://localhost/socket.io/?EIO=3&transport=polling&t=1422782885332-41 +1ms
socket.io.js:3715 engine.io-client:polling-xhr xhr data null +0ms
socket.io.js:3715 engine.io-client:socket setting transport polling +1ms
socket.io.js:1402 socket.io-client:manager connect attempt will timeout after 20000 +3ms

Personne ne sait comment corriger cette erreur. J'ai trouvé cette discussion, mais ont été incapables de résoudre le problème.

OriginalL'auteur fraxture | 2015-02-01