1

我正在尝试从 python 调用 socketio 函数,但我收到以下错误消息:

NoSocket: There are no clients on the channel: global

由于我刚开始使用socketio,我对它并不熟悉,所以我想知道为什么会出现这个错误。

这是蟒蛇:

print "starting test"
while s <= total:
print total
    percent = (100 * s) / total
    print percent
    res["data"]["value"] = percent
    socket.broadcast_channel(json.dumps(res), channel="global")
    time.sleep(1)
    s = s + 1
print "test is over"

这是socketio部分:

var socket = new io.Socket();
socket.connect();
socket.subscribe('global');

console.log('subscribed');

socket.on('message', function (message) {
var data = JSON.parse(message);
if (data.type == "init") {
    console.log("Receiving Init info");
}
else if (data.type == "record") {
    console.log("Receiving record info");
if (data.data.object == "progress-bar") {
        var elem = document.getElementById("myBar");
        elem.style.width = data.data.value + '%';
        document.getElementById("label").innerHTML = data.data.value * 1 + '%';
}
}
else {
    console.log("Receiving unknown data type : " + JSON.stringify(data));
}
});

知道为什么吗?提前致谢。

4

0 回答 0