有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 安卓 Signal hubconnection应用程序与服务器协商失败

嗨,我是安卓开发的新手,我想写一个使用signalR java客户端的应用程序。在第一步中,我回答了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 安卓 client").get();
    System.out.println("sent!!!");
} catch (InterruptedException e) {
    e.printStackTrace();
} catch (ExecutionException e) {
    e.printStackTrace();
}

你可以从here下载服务器代码

我在^{中有以下错误

错误:

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访问集线器,但如何在安卓上实现,以便我的应用程序可以连接

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

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=安卓;+version=2.0) - 404 0 2 3

共 (2) 个答案

  1. # 1 楼答案

    localhost不适合我,我不得不部署asp。net web应用程序,允许在防火墙入站规则中使用该端口,并将其放入android中的信号器配置中。。希望这能帮助别人。。。干杯

  2. # 2 楼答案

    更改了String host = "localhost";

    String host = "localhost/signalr";