我正在尝试从python调用socketio函数,但是我收到以下错误消息:
NoSocket: There are no clients on the channel: global
由于我刚刚开始使用socketio,我对它不熟悉,所以我想知道为什么会出现这个错误。
这是python:
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));
}
});
知道为什么吗?提前谢谢。