WebSocket到localhost无法在Microsoft Edge上运行 [英] WebSocket to localhost not working on Microsoft Edge
问题描述
我创建了一个简单的WebSocket服务器,并尝试使用以下代码连接到它:
I've created a simple WebSocket server and am trying to connect to it with the following code:
function test(name) {
var ws = new WebSocket('ws://localhost:1234');
ws.onopen = function () {
ws.send('Hello from ' + name);
}
}
test('Edge');
这适用于Windows10上的Chrome和IE11,但是当我尝试使用Edge时, onopen
函数未被调用,而是最终我得到以下错误:
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:
SCRIPT12029:WebSocket错误:网络错误12029,无法建立与服务器的连接
SCRIPT12029: WebSocket Error: Network Error 12029, A connection with the server could not be established
版本 12.10240 边缘
有人问及类似的问题这里但错误信息不同。
A similar problem was asked about here but the error message is different.
我尝试过的事情:
- IP -
localhost
,127.0.0.1
,实际IP - 允许localhost环回标志 - 打开和关闭
- IP -
localhost
,127.0.0.1
, the actual IP - Allow localhost loopback flag - both on and off
当尝试与另一台机器通信时,问题不会发生。
When trying to communicate with a different machine the problem does not occur.
这是Edge中的缺陷还是我做错了什么?
Is this a defect in Edge or am I doing something wrong?
推荐答案
我遇到了类似的问题,但是实际导航到浏览器中的页面时。我可以使用短语localhost,它工作正常,但当我使用我的机器名称时,我没有工作。我找到了此论坛,他们建议您在管理员提示中运行以下命令:
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 forum where they suggested that you run the following command in a administrator prompt:
CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe
为我工作。您可能会看到某种形式的同一问题。
Worked for me. Thought you might be seeing some form of the same issue.
正如论坛建议的那样,您现在也可以通过打开Edge并导航到 about:flags ,然后在Developer Settings下勾选允许localhost环回(这可能会使您的设备面临风险)。应该感觉比将随机内容粘贴到命令提示符更安全。
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.
编辑:正如tresf指出的那样,环回about:flags中的复选框似乎已停止工作(作为修复),因此您将使用CheckNetIsolation命令,以使Edge免除。
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.
这篇关于WebSocket到localhost无法在Microsoft Edge上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!