Socket.io回到XHR民意调查

时间:2014-12-08 20:21:25

标签: javascript node.js sockets websocket socket.io

我有一个Express,Node和Socket.io应用程序,当我检查Network时,我可以看到Socket正在回退到XHR reuqests而不是WebSockets。

我错过了一些明显的东西吗?

在我的控制台中,我看到,在我的“网络”选项卡中,我看不到WebSocket,只是对socket.io的XHR请求:

WebSocket connection to 'ws://localhost/socket.io/?EIO=3&transport=websocket&sid=lVFuwHcH-XPm8zHhAAAA' failed: Error in connection establishment: net::ERR_SOCKS_CONNECTION_FAILED

服务器代码:

var app         = express(),
    http        = require('http').Server(app),
    io          = require('socket.io')(http),

io.on("connection", function (socket) {
    var interval = setInterval(function () {
        if(nt == ""){
            socket.emit("message", {"data": "<strong>Waiting for data...</strong>"});
        }else{
            socket.emit("data", {
                "mediumLoadTime": nt.mediumPageLoad(),
                "firstLoadTime": nt.times[0],
                "lastLoadTime": nt.times[nt.times.length-1],
                //"times": nt.times,
                "requests": nt.reqMade.toString(),
                "success": nt.successful.toString(),
                "error": nt.error.toString(),
                "virtualusers": nt.virtualUsers.toString(),
                "host": nt.options.host.toString(),
            });
        }
    }, 10);

    socket.on("disconnect", function () {
        clearInterval(interval);
    });
});

客户端:

var socket = io();


   socket.on('data', function (data) {
        console.log(data);
   });

在我看来,我需要<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>

0 个答案:

没有答案