Websocekt连接在Internet Explorer 11中不起作用

时间:2019-07-08 08:30:22

标签: javascript websocket internet-explorer-11

我有下面的Java脚本,应该通过调用来使用 initConnection(“ User_1”,50123);

这在Firefox中可以正常工作,但是就Internet Explorer(11)而言似乎无法正常工作,我对它破裂的地方感到有些困惑。

const g_PROT = "ws://";
const g_HOST = "127.0.0.1";
const g_INTERVAL = 5000;
const g_CONT = "_CONTINUE";

function initConnection(beatMessage, port) {
    var url = g_PROT + g_HOST + ":" + port;
    ws = new WebSocket(url);
    ws.onopen = function () {
        console.log("WebSocket connection starting for message: " + beatMessage);
    };
    window['beatMessage'] = beatMessage;

    // Heart Beat
    window.setInterval(function () {
        var aliveMessage = beatMessage + g_CONT;
        ws.send(aliveMessage);
    }, g_INTERVAL);

    var aliveMessage = beatMessage + g_CONT;
    ws.send(aliveMessage);
}

// Send close message
window.onbeforeunload = function (e) {
    var closeMessage = beatMessage + "_CLOSING";
    ws.send(closeMessage);
};

在控制台中,我得到:SCRIPT5022: InvalidStateError,参考在initConnection方法中调用var aliveMessage = beatMessage + g_CONT;的那一行

0 个答案:

没有答案