【问题标题】:SignalR not working on raspberry with windows 10SignalR 不适用于 Windows 10 的覆盆子
【发布时间】:2016-04-26 00:09:40
【问题描述】:

我的服务器和自定义测试客户端之间的通信正常。

我从我的 UWP 添加一个连接并在我的本地窗口上运行它,它正在工作。

当我在运行 win iot 核心的树莓派上部署我的 UWP 时,没有收到信号,输出中没有显示错误。

服务器:

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

我不知道接下来要检查/做什么。

当我的应用在我的 PI 上运行时,为什么没有收到消息?

【问题讨论】:

  • 可以在服务器端捕获数据包以查看客户端是否连接到它。检查并发布您发现的内容。

标签: c# raspberry-pi signalr win-universal-app


【解决方案1】:

您也在 Pi 上收听 localhost。使用那里的服务器 PC 的 IP 地址或主机名作为 url 侦听该服务器。


如果这是您问题的答案,请将其标记为答案。

【讨论】:

  • 这是问题的一部分,我还在服务器上更改为我的局域网 IP,然后在 UWP 应用程序中我还不得不禁用我的防火墙,因为树莓派上的应用程序无法连接,这次抛出了一些错误,我将在我的防火墙中添加一条规则。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-03
  • 2018-05-31
  • 1970-01-01
相关资源
最近更新 更多