嗨,我是 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
最佳答案
更改了String host =“localhost”;
到字符串主机=“localhost/signalr”;
关于java - android signalR hub连接应用程序与服务器协商失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33646318/