socket.io在Chrome中不工作

socket.io在Chrome中不工作,socket.io,Socket.io,我正在尝试这个简单的socket.io示例,它在Safari中工作(从两侧发送/接收)。但是,在Chrome浏览器中,客户端接收消息,但服务器不会接收客户端发送的消息 index.html <!doctype html> <html> <head> <title>web sockets</title> <meta charset="utf-8"> <script src="/socket.io/socket.io.js

我正在尝试这个简单的socket.io示例,它在Safari中工作(从两侧发送/接收)。但是,在Chrome浏览器中,客户端接收消息,但服务器不会接收客户端发送的消息

index.html

<!doctype html>
<html>
<head>
<title>web sockets</title>
<meta charset="utf-8">
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:8888');
socket.on('news', function (data) {
    console.log(data);
    writeMessage(data);
    socket.emit('my other event', { my: 'data' });
});

function writeMessage(msg) {
    var msgArea = document.getElementById("msgArea");
    if (typeof msg == "object") {
        msgArea.innerHTML = msg.hello;
    }
    else {
        msgArea.innerHTML = msg;
    }
}
</script>
</head>
<body>
<div id="msgArea">
</div>
</body>
</html>

我错过什么了吗?Chrome在v.19上

您可以使用它来查看问题是否出在您的浏览器/代理或代码上。

您确定dev.intulect.com:8888吗?因为我在本地主机上托管了同一个应用程序,而且它(在chrome中)似乎可以正常工作。是的……这只是我确认的一个虚拟主机。我也试过使用localhost。这一切都在safari中运行…只是不在chromei还应该补充一点,它在firefox v13中也不工作。你使用的是什么版本的Socket.io?Chrome、Websocket上使用了什么传输?您是否尝试删除“writeMessage(data);”?也许DOM还没准备好。
var app = require('http').createServer(handler)
  , io = require('/usr/local/lib/node_modules/socket.io').listen(app)
  , fs = require('fs')

app.listen(8888);

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.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});