2

hi i'm new in android developing and i want to write an application which use signalR java-client. in first step i did the answer of this and here is my client code:

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

and u can download the server code from here

i have following error with awaitConnection.get();

error:

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

i also have this error:

Caused by: microsoft.aspnet.signalr.client.http.InvalidHttpStatusCodeException:Invalid status code: 404

can anyone please help me? i searched a lot but i didn't found anything helpful for me

EDIT:

clients can access the hub via this but how can i implement on android so my application can connect?

this is the log file on server:

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
Community
  • 1
  • 1
Sina
  • 275
  • 5
  • 15
  • 1
    You can read my answers at http://stackoverflow.com/questions/32505390/signalr-integration-in-android-studio/32516840#32516840 and http://stackoverflow.com/questions/32573823/how-to-use-signalr-in-android/32574829#32574829, hope this helps! – BNK Nov 11 '15 at 09:05
  • @BNK thanks for your reply. i used your signalR service class but still having same issue!! i'm getting 404 file or directory not found! i added the log in my server. can you help? – Sina Nov 11 '15 at 09:54
  • Make sure you can access the server url from android phone/emulator. Try using web browser in the phone. Don't forget setting INTERNET permission in AndroidManifest.xml file. – BNK Nov 11 '15 at 10:06
  • @BNK i found the problem. thanks to you and sorry for taking your time – Sina Nov 11 '15 at 10:24
  • You're welcome, happy coding :) – BNK Nov 11 '15 at 10:26

2 Answers2

2

changed the String host = "localhost";

to String host = "localhost/signalr";

Sina
  • 275
  • 5
  • 15
0

localhost didn't work for me, i had to deploy the asp.net web application on IIS, allow the port in Firewall inbound rules and put it in signalr config in android.. hope this helps someone... Cheers!