WebSocket to localhost not working on Microsoft Edge

我怕爱的太早我们不能终老 提交于 2019-11-29 14:00:03

问题


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');

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 Error: Network Error 12029, A connection with the server could not be established

This is happening for version 12.10240 of Edge.

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

Things I tried:

  • 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.

Is this a defect in Edge or am I doing something wrong?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/31772564/websocket-to-localhost-not-working-on-microsoft-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!