0

我们需要将本机应用程序与 Web 应用程序进行通信。

我们认为使用信号器来发送消息/命令。

管道将是:

  • 用户单击以执行操作。
  • Javascript(带有信号器)向天蓝色的服务器发送消息。
  • 服务器将消息重新发送给特定的客户端。它必须是安装在同一台机器上的客户端。
  • 结果完成后,NET 将返回结果。

问题是,如何在信号服务器的同一台机器上找到客户端?

我们系统中的组织是:

  • 有中心/健身房。
  • 每个中心都有可以登录的工作人员。

我们可以通过一些文件配置来识别同一中心的客户。例如,保存我们的密钥中心。但是,在一个中心,是否可以在不同的计算机上安装多个.NET 客户端。

我们认为使用计算机的私有 IP 在信号服务器上制作密钥。

var ips = [];

    var RTCPeerConnection = window.RTCPeerConnection ||
        window.webkitRTCPeerConnection || window.mozRTCPeerConnection;

    var pc = new RTCPeerConnection({
        // Don't specify any stun/turn servers, otherwise you will
        // also find your public IP addresses.
        iceServers: []
    });
    // Add a media line, this is needed to activate candidate gathering.
    pc.createDataChannel('');

    // onicecandidate is triggered whenever a candidate has been found.
    pc.onicecandidate = function (e) {
        if (!e.candidate) { // Candidate gathering completed.
            pc.close();
            console.log(ips);
            return;
        }
        var ip = /^candidate:.+ (\S+) \d+ typ/.exec(e.candidate.candidate)[1];

        ips.push(ip);
    };
    pc.createOffer(function (sdp) {
        pc.setLocalDescription(sdp);
    }, function onerror() { });

可以在 .NET 客户端中毫无问题地获取此数据。但是在 javascript 中,之前的代码可以正常工作。在某些 PC 中,它只返回 ipv4。在 Mozilla 中它不起作用。

我们如何识别这两个客户?你知道达到目标的另一种方法吗?

谢谢,

4

1 回答 1

0

最后,我们没有找到过滤ip地址的好办法。

我们做了如下:

我们使用 URI 模式来启动我们的应用程序。URI 架构窗口

    公共类注册器URI


        常量 URI_SCHEME As String = "xxx"
        常量 URI_KEY As String = "URL:xxx"
        Private Shared APP_PATH As String = Location.AssemblyDirectory() ' "C:\Program Files (x86)\xxx.exe"

        公共共享子 RegisterUriScheme()

            使用 hkcrClass 作为 RegistryKey = Registry.ClassesRoot.CreateSubKey(URI_SCHEME)
                hkcrClass.SetValue(Nothing, URI_KEY)
                hkcrClass.SetValue("URL 协议", [String].Empty, RegistryValueKind.[String])

                使用 defaultIcon 作为 RegistryKey = hkcrClass.CreateSubKey("DefaultIcon")
                    Dim iconValue As String = [String].Format("""{0}"",0", APP_PATH)
                    defaultIcon.SetValue(无,iconValue)
                结束使用

                使用 shell 作为 RegistryKey = hkcrClass.CreateSubKey("shell")
                    使用 open As RegistryKey = shell.CreateSubKey("open")
                        使用命令 As RegistryKey = open.CreateSubKey("command")
                            Dim cmdValue As String = [String].Format("""{0}"" ""%1""", APP_PATH)
                            command.SetValue(无,cmdValue)
                        结束使用
                    结束使用
                结束使用
            结束使用
        结束子

    结束类

在 Azure WebApp 中,我们启动 SignalR 服务器。该服务器会将数据从我们的 .NET 应用程序发送到 Chrome。

为了实现这一点,当加载网络时,我们连接到 signalR 服务器。为了构建 de uri,我们将 connectionId 从 Javascript 客户端发送到 .NET 客户端。

然后,当本机进程完成时。.NET 客户端将信息发送到 signalR 服务器,该服务器使用 connectionId 将数据镜像到 javacript 客户端。

为了避免启动我们本机应用程序的某些实例,我们使用 IPC 通道将数据发送到前一个实例并关闭新实例。

链接到源博客源

于 2017-07-04T19:28:11.210 回答