使用 SignalR 连接到 WinForm 服务器?

Connect to WinForm server using SignalR?

我已经下载了 SignalR 的官方示例,当我尝试从 WinFormsClient 连接到 WinFormsServer 时,它工作正常。一切都很好...

我下载了 android 的 SignalR 并尝试使用下面的代码建立连接,但始终没有成功...我只得到 SocketTimeoutException。这是我的代码,也许有人可以帮助我!

我正在真实设备上尝试这个。 PC 和设备都在同一个 wifi 网络上。

@Override
public void onClick(View v) {

    Platform.loadPlatformComponent(new AndroidPlatformComponent());
    String host = "http://192.168.0.11:8080/signalr";
    HubConnection connection = new HubConnection(host);
    HubProxy proxy = connection.createHubProxy("MyHub");

    SignalRFuture<Void> awaitConnection = connection.start();
    try {
        awaitConnection.get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    proxy.invoke("Send", new String[]{"Hahahahahhahaha", "shit shit shit!"});
    proxy.on("AddMessage", new SubscriptionHandler2<String, String>() {
        @Override
        public void run(String p1, String p2) {
            Log.d("result := ", p1 + " ---- " + p2);
        }
    }, String.class, String.class); }
});

您的防火墙可能会阻止连接。