WebSocket to localhost 在 Microsoft Edge 上不起作用 [英] WebSocket to localhost not working on Microsoft Edge

查看:35
本文介绍了WebSocket to localhost 在 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

Edge 的 12.10240 版本正在发生这种情况.

This is happening for version 12.10240 of Edge.

here 中询问了类似的问题,但是错误消息是不同的.

A similar problem was asked about here but the error message is different.

我尝试过的事情:

  • IP - localhost127.0.0.1,实际IP
  • 允许本地主机环回标志 - 开启和关闭
  • 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",然后勾选允许本地主机环回(这可能会使您的设备有风险)"下的开发人员设置".应该比将随机内容粘贴到命令提示符中更安全一些.

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 to localhost 在 Microsoft Edge 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆