2016-04-24 59 views
2

我的服務器和自定義測試客戶端之間的通信正在工作。SignalR不能在windows上使用覆盆子10

我從我的UWP添加一個連接,並在我的本地窗口上運行它,它正在工作。

當我將我的UWP部署在運行win iot核心的樹莓上時,信號未收到,輸出中未顯示錯誤。

服務器:

class Program 
{ 
    static void Main(string[] args) 
    { 
     // This will *ONLY* bind to localhost, if you want to bind to all addresses 
     // use http://*:8080 to bind to all addresses. 
     // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx 
     // for more information. 
     string url = "http://localhost:8080"; 
     using (WebApp.Start<Startup>(url)) 
     { 
      Console.WriteLine("Server running on {0}", url); 
      Console.ReadLine(); 
     } 
    } 
} 
public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     app.UseCors(CorsOptions.AllowAll); 
     app.MapSignalR(); 
    } 
} 

TestClient的:

public class Program 
{ 
    public static void Main(string[] args) 
    { 
     //Set connection 
     string url = "http://localhost:8080"; 
     var connection = new HubConnection(url); 
     //Make proxy to hub based on hub name on server 
     var myHub = connection.CreateHubProxy("TestHub"); 
     //Start connection 

     connection.Start(); 

     while (true) 
     { 
      Console.ReadLine(); 
      myHub.Invoke("SendSignal"); 
     } 
    } 
} 

UWP APP:

InitializeComponent(); 

pushButtonValue = GpioPinValue.High; 
InitGPIO(); 

//Set connection 
string url = "http://localhost:8080"; 
var connection = new HubConnection(url); 
//Make proxy to hub based on hub name on server 
var myHub = connection.CreateHubProxy("TestHub"); 

//Start connection  
myHub.On("ReceiveSignal", FlipLED); 
connection.Start(); 


//timer = new DispatcherTimer(); 
//timer.Interval = TimeSpan.FromMilliseconds(50); 
//timer.Tick += Timer_Tick; 
//timer.Start(); 

我不知道到c嘿/做下一個。

爲什麼當我的應用在我的PI上運行時收不到消息?

+0

可以在服務器端捕獲數據包以查看客戶端是否連接到它。檢查併發布您找到的內容。 –

回答

1

您也正在收聽Pi上的localhost。使用服務器PC的IP地址或主機名稱作爲URL來偵聽該服務器。


如果這是您的問題的答案,請將其標記爲答案。

+0

這是問題的一部分,我也在服務器上更改爲我的LAN IP和UWP應用程序 然後我也必須禁用我的防火牆,因爲在樹莓上的應用程序無法連接,這次拋出了一些錯誤,我將添加一條規則到我的防火牆。 –

+0

感謝@Martin,發現ip –