javascript WebSocket to localhost 在 Microsoft Edge 上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31772564/
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
WebSocket to localhost not working on Microsoft Edge
提问by Motti
I've created a simple WebSocket server and am trying to connect to it with the following code:
我创建了一个简单的 WebSocket 服务器,并尝试使用以下代码连接到它:
function test(name) {
var ws = new WebSocket('ws://localhost:1234');
ws.onopen = function () {
ws.send('Hello from ' + name);
}
}
test('Edge');
This works fine from Chrome and IE11 on Windows10 but when I try from Edge, the onopen
function isn't called, instead I eventually get the following error:
这在 Windows10 上的 Chrome 和 IE11 上运行良好,但是当我从 Edge 尝试时,该onopen
函数没有被调用,而是最终出现以下错误:
SCRIPT12029: WebSocket Error: Network Error 12029, A connection with the server could not be established
SCRIPT12029:WebSocket 错误:网络错误 12029,无法建立与服务器的连接
This is happening for version 12.10240of Edge.
Edge 12.10240版本正在发生这种情况。
A similar problem was asked about herebut the error message is different.
在这里询问了类似的问题,但错误消息不同。
Things I tried:
我尝试过的事情:
- IP-
localhost
,127.0.0.1
, the actual IP - Allow localhost loopbackflag - both on and off
- IP-
localhost
,127.0.0.1
, 实际IP - 允许本地主机环回标志 - 开启和关闭
When trying to communicate with a different machine the problem does not occur.
当尝试与不同的机器通信时,问题不会发生。
Is this a defect in Edge or am I doing something wrong?
这是 Edge 的缺陷还是我做错了什么?
回答by Jools
I had a similar problem, but it was when actually navigating to pages in the browser. I could use the phrase localhost and it worked fine, but I didn't work when I used my machine's name. I found this forumwhere they suggested that you run the following command in a administrator prompt:
我有一个类似的问题,但它是在实际导航到浏览器中的页面时。我可以使用短语 localhost 并且它工作正常,但是当我使用我的机器名称时我没有工作。我找到了这个论坛,他们建议您在管理员提示符下运行以下命令:
CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe
Worked for me. Thought you might be seeing some form of the same issue.
对我来说有效。以为您可能会看到某种形式的相同问题。
As the forum suggests, you can now also do this by opening Edge and navigating to "about:flags", then tick "Allow localhost loopback (this might put your device at risk)" under "Developer Settings". Should feel a little safer than pasting random stuff into your command prompt.
正如论坛建议的那样,您现在也可以通过打开 Edge 并导航到“ about:flags”,然后在“开发人员设置”下勾选“允许本地主机环回(这可能会使您的设备处于危险之中)”来执行此操作。应该比将随机内容粘贴到命令提示符中更安全一些。
Edit:As tresf pointed out below, the loopback checkbox in the about:flags appears to have stopped working (as a fix), so you'll have use the CheckNetIsolation command, to make Edge exempt.
编辑:正如下面 tresf 所指出的,about:flags 中的环回复选框似乎已停止工作(作为修复),因此您必须使用 CheckNetIsolation 命令来使 Edge 免除。