javascript Websocket 连接关闭,错误 1006 (Webdis)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22645808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:30:36  来源:igfitidea点击:

Websocket connection closes with error 1006 (Webdis)

javascriptwebsocketrediswebdis

提问by Andrew Roo

I'm using Redis + Webdis on Debian 7 32.

我在 Debian 7 32 上使用 Redis + Webdis。

My issue is that all websocket connections are closed with the exit code 1006 after completing the first command (except the "SUBSCRIBE" one). For example, for this testJSON() function

我的问题是,在完成第一个命令(“订阅”命令除外)后,所有 websocket 连接都关闭,退出代码为 1006。例如,对于这个 testJSON() 函数

function testJSON() {
  var jsonSocket = new WebSocket("ws://ip:7379/.json");
  jsonSocket.onopen = function() {
    console.log("JSON socket connected!");
    jsonSocket.send(JSON.stringify(["SET", "hello", "world"]));
    jsonSocket.send(JSON.stringify(["GET", "hello"]));
  };
  jsonSocket.onmessage = function(messageEvent) {
    console.log("JSON received:", messageEvent.data);
  };
  jsonSocket.onclose = function(messageEvent) {
    //some logging
  };
  jsonSocket.onerror = function(messageEvent) {
    //some logging
  };
}
testJSON();

i'm getting (in Firebug)

我得到(在 Firebug 中)

JSON socket connected!
JSON received: {"SET":[true,"OK"]}
onClose: error.code 1006

The onError event is'nt working, and after the {"SET":[true,"OK"]} response my connection closes. GET command is'nt working too. Same behavior in Firefox and Chrome. I checked the headers, it seems they are valid.

onError 事件不起作用,在 {"SET":[true,"OK"]} 响应之后我的连接关闭。GET 命令也不起作用。Firefox 和 Chrome 中的行为相同。我检查了标题,似乎它们是有效的。

Any suggestions?

有什么建议?

回答by Andrew Roo

Ok, it's a feature, not bug. In code (websocket.c):

好吧,这是一个功能,而不是错误。在代码中(websocket.c):

if (cmd_is_subscribe(cmd)) {
    r->keep_alive = 1;
}

Changing this code solved part of my problems, but not all of them.

更改此代码解决了我的部分问题,但不是全部。