Home>

I want to communicate with a native application created in C # using WebSocket from a web application on an external web server using Microsoft Edge.
You can communicate from Internet Explorer 11 or Google Chrome.

Error message

If i look at Edge debugger
SCRIPT12029: SCRIPT12029: WebSocket Error: Network Error 12029, could not connect to server
It will be displayed.

Applicable source code

JavaScript source

function connectSocketServer (callback) {
var support ="MozWebSocket"in window?'MozWebSocket': ("WebSocket"in window?'WebSocket': null);
if (support == null) {
return;
}
if (ws! = null) {
ws.close ();
}
console.log ("* Connecting to server ..");
// create a new websocket and connect
ws = new window [support] ('ws: // localhost: 2012');

ws.onmessage = function (evt) {
var json = evt.data;
var data = JSON.parse (json);
if (data ["command"] =="add_message_to_browser") {
var message ="["+ data ["time"] +"] received:"+ data ["message"];
add_message (message);
}
};
ws.onopen = function () {
console.log ('* Connection open');
if (typeof callback! ="undefined") {
callback (&​​quot;open");
}
};
ws.onclose = function () {
console.log ('* Connection closed');
if (typeof callback! ="undefined") {
callback (&​​quot;close");
}
}
}

C # source
private void Form1_Load (object sender, EventArgs e)
{
frm = this;
try {
var server_config = new SuperSocket.SocketBase.Config.ServerConfig ()
{
Port = 2012,
Ip ="Any" ;,
MaxConnectionNumber = 100,
Mode = SuperSocket.SocketBase.SocketMode.Tcp,
Name ="SuperWebSocket Server" ;,
MaxRequestLength = 1024 * 1024 * 10,
};
setup_server (ref server, server_config);
}
catch (Exception ex)
{
MessageBox.Show ("Application startup failed.&Quot;);
Application.Exit ();
}
}
private void setup_server (ref WebSocketServer server, SuperSocket.SocketBase.Config.ServerConfig serverConfig)
{
var rootConfig = new SuperSocket.SocketBase.Config.RootConfig ();
server = new SuperWebSocket.WebSocketServer ();
server.Setup (rootConfig, serverConfig);
// Event handler settings
server.NewSessionConnected + = HandleServerNewSessionConnected;
// message received
server.NewMessageReceived + = HandleServerNewMessageReceived;
// disconnect
server.SessionClosed + = HandleServerSessionClosed;
// Start server
server.Start ();
}

Tried

You can communicate from Internet Explorer 11 and Google Chrome under the same conditions.
You can also communicate with Edge from a web application launched from local IIS.
InternetExplorer11 was not able to communicate at first, but it was able to communicate if Internet option->Security->Local Internet "I was in another zone ..." was unchecked. Edge was able to communicate with about: flags, although "Allow localhost loopback" was checked. In addition, the situation was the same even when communicating with wss. Is it due to cross domain?
Thank you.

Supplemental information (FW/tool version etc.)

The local computer is running only Difender on Windows 10.

  • Answer # 1

    I think loopback is not allowed in Windows settings.
    https://github.com/tiagonmas/Windows-Loopback-Exemption-Manager
    Please allow at.


    Appendix

    If you looked at Edge help, there was a description of how to set from the command line.
    https://developer.microsoft.com/en-us/microsoft-edge/platform/faq/#how-can-i-debug-localhost
    Please refer to.

      

    Microsoft Edge allows localhost access by default but treats "localhost" as an Internet site, so Intranet features like integrated authentication are disabled.
      Some custom host mappings might require additional configuration (more on that here) for which you can run the following command:
      CheckNetIsolation LoopbackExempt -a -n ="Microsoft.MicrosoftEdge_8wekyb3d8bbwe"

  • Answer # 2

    If you're referring to local HTML on Edge, you can't communicate with WebSocket.
    As shown in the sample below, when HTML is installed on the Internet, it can communicate with Edge.
    https://github.com/tekka/ParallelHybridApp
    (The certificate has expired, so I renewed it.)

    Please refer here.
    https://qiita.com/tekka/items/1bf440ccd50bb4171886

    Addition:
    Briefly describe how to apply a regular SSL certificate to the local native app server.

    Rent a server such as VPS

    Obtain a domain from Mu Mu domain etc. and point it to the server

    Install LetsEncrypt on the server and get a wildcard certificate

    Set a subdomain for the domain and point it to the local host (127.0.0.1)

    Convert the private key of the acquired wildcard certificate to pfx format and install it in the native app

    In the sample above, the certificate is verified on the native application side, and if it expires, the logic to download the SSL certificate from the specified server is included.
    If you use route53 etc. instead of Mu Mu domain, LetsEncrypt update should be able to be automated, but it has not been verified yet.