android signalR hubconnection应用程序协商与服务器失败

时间:2015-11-11 07:58:30

标签: java signalr

嗨,我是android开发的新手,我想编写一个使用signalR java-client的应用程序。在第一步中,我做了this的答案,这是我的客户代码:

Platform.loadPlatformComponent(new AndroidPlatformComponent());
String host = "localhost";
HubConnection connection = new HubConnection( host);
HubProxy hub = connection.createHubProxy("HubConnectionAPI");

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

hub.subscribe(this);
try {
    hub.invoke("DisplayMessageAll", "message from android client").get();
    System.out.println("sent!!!");
} catch (InterruptedException e) {
    e.printStackTrace();
} catch (ExecutionException e) {
    e.printStackTrace();
}

您可以从here

下载服务器代码

我在awaitConnection.get();

时遇到以下错误

错误:

W/System.err: java.util.concurrent.ExecutionException: microsoft.aspnet.signalr.client.transport.NegotiationException: There was a problem in the negotiation with the server

我也有这个错误:

Caused by: microsoft.aspnet.signalr.client.http.InvalidHttpStatusCodeException:Invalid status code: 404
谁能帮助我吗?我搜索了很多,但我没有找到任何对我有用的东西

修改

客户可以通过this访问集线器,但我如何在Android上实现,以便我的应用程序可以连接?

这是服务器上的日志文件:

2015-11-11 09:05:08 10.2.0.18 GET /signalr/negotiate clientProtocol=1.3&connectionData=%5B%7B%22name%22%3A%22hubconnectionapi%22%7D%5D 80 - 10.2.0.253 SignalR+(lang=Java;+os=android;+version=2.0) - 404 0 2 3

2 个答案:

答案 0 :(得分:1)

更改了String host = "localhost";

String host = "localhost/signalr";

答案 1 :(得分:0)

localhost不适用于我,我不得不在IIS上部署asp.net Web应用程序,允许防火墙入站规则中的端口并将其放入android中的signalr配置中。希望这有助于某人......干杯!

相关问题