Javascript “WebSocket 在建立连接之前关闭”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12487828/
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
What does "WebSocket is closed before the connection is established" mean?
提问by user1144112
I'm using JavaScript and the Union platformHow would I go about diagnosing this problem? Many thanks.
我正在使用 JavaScript 和Union 平台我将如何诊断这个问题?非常感谢。
回答by leggetter
If you go to http://jsbin.com/ekusep/6/editand view the JavaScript console you'll see the 'WebSocket is closed before the connection is established' logged. I've tested this in Chrome.
如果您转到http://jsbin.com/ekusep/6/edit并查看 JavaScript 控制台,您将看到记录的“WebSocket 在建立连接之前已关闭”。我已经在 Chrome 中测试过了。
In this code what it means is that ws.close()
was called (by user code) before the connection was even given a chance to be established.
在这段代码中,它的意思是ws.close()
在甚至有机会建立连接之前(由用户代码)调用。
So, the cause of this error is if code attempts to close the WebSocket connection before it's had a chance to actually connect.
因此,此错误的原因是代码是否在有机会实际连接之前尝试关闭 WebSocket 连接。