2017-05-20 42 views
0

我們需要將本機應用程序與Web應用程序進行通信。信號發送器從瀏覽器發送到同一臺機器上的.net客戶端

我們認爲使用信號發送消息/命令。

管道是:

  • 用戶點擊做出的動作。
  • Javascript(with signalr)發送消息到服務器在天藍色。
  • 服務器重新發送消息一個特定的客戶端。它必須是安裝在同一臺計算機上的客戶端。
  • 一旦結果完成,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中它不起作用。

我們如何識別兩個客戶?你知道另一種達到目標的方式嗎?

謝謝,

+0

也許另一選項將是使用[URI方案](https://blogs.msdn.microsoft.com/noahc/2006/10/19/register-a-custom-url-協議處理程序/)啓動我們的應用程序,並通過信號發送結果。 –

回答

0

最後,我們沒有找到一個很好的解決方案過濾ip地址。

我們做了如下:

我們使用URI模式來啓動我們的應用程序。 URI Schema windows

 

    Public Class RegistrarURI 


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

     Public Shared Sub RegisterUriScheme() 

      Using hkcrClass As RegistryKey = Registry.ClassesRoot.CreateSubKey(URI_SCHEME) 
       hkcrClass.SetValue(Nothing, URI_KEY) 
       hkcrClass.SetValue("URL Protocol", [String].Empty, RegistryValueKind.[String]) 

       Using defaultIcon As RegistryKey = hkcrClass.CreateSubKey("DefaultIcon") 
        Dim iconValue As String = [String].Format("""{0}"",0", APP_PATH) 
        defaultIcon.SetValue(Nothing, iconValue) 
       End Using 

       Using shell As RegistryKey = hkcrClass.CreateSubKey("shell") 
        Using open As RegistryKey = shell.CreateSubKey("open") 
         Using command As RegistryKey = open.CreateSubKey("command") 
          Dim cmdValue As String = [String].Format("""{0}"" ""%1""", APP_PATH) 
          command.SetValue(Nothing, cmdValue) 
         End Using 
        End Using 
       End Using 
      End Using 
     End Sub 

    End Class 

在Azure WebApp中,我們啓動SignalR Server。該服務器會將我們的.NET應用程序的數據發送到Chrome。

爲了達到這個目的,當web加載時,我們連接到signalR服務器。爲了構建de uri,我們從Javascript客戶端發送connectionId到.NET客戶端。

然後,當原生過程完成。 .NET客戶端將信息發送到signalR服務器,並且此服務器使用connectionId將數據鏡像到javacript客戶端。

爲了避免啓動我們的本地應用程序的某個實例,我們使用IPC通道將數據發送到一個實例,並關閉新的實例。

鏈接到源Blog source

相關問題