Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal R Native Android app Negotiation Failed

I'm trying to create an android app that could connect to my basic SignalR Hub.

Its just a basic Hub file i want to test things out with but I've had no luck so far. Could someone have a look at the thing(s) I'm doing wrong? Every time I try to run it I get the following stackraces:

05-27 09:10:39.785  22247-22247/nl.vict.chatapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<microsoft.aspnet.signalr.client.transport.WebsocketTransport$1>
05-27 09:10:39.785  22247-22247/nl.vict.chatapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<microsoft.aspnet.signalr.client.transport.WebsocketTransport$1>
05-27 09:10:39.829  22247-22266/nl.vict.chatapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<microsoft.aspnet.signalr.client.transport.WebsocketTransport$1>
05-27 09:10:39.830  22247-22247/nl.vict.chatapp W/System.err﹕ java.util.concurrent.ExecutionException: microsoft.aspnet.signalr.client.transport.NegotiationException: There was a problem in the negotiation with the server
05-27 09:10:39.830  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.SignalRFuture.get(SignalRFuture.java:112)
05-27 09:10:39.830  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.SignalRFuture.get(SignalRFuture.java:102)
05-27 09:10:39.830  22247-22247/nl.vict.chatapp W/System.err﹕ at nl.vict.chatapp.MainActivity.onCreate(MainActivity.java:48)
05-27 09:10:39.831  22247-22247/nl.vict.chatapp W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5937)
05-27 09:10:39.831  22247-22247/nl.vict.chatapp W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
05-27 09:10:39.832  22247-22247/nl.vict.chatapp W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
05-27 09:10:39.832  22247-22247/nl.vict.chatapp W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
05-27 09:10:39.832  22247-22247/nl.vict.chatapp W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144)
05-27 09:10:39.833  22247-22247/nl.vict.chatapp W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
05-27 09:10:39.833  22247-22247/nl.vict.chatapp W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
05-27 09:10:39.833  22247-22247/nl.vict.chatapp W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
05-27 09:10:39.833  22247-22247/nl.vict.chatapp W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
05-27 09:10:39.834  22247-22247/nl.vict.chatapp W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
05-27 09:10:39.834  22247-22247/nl.vict.chatapp W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ Caused by: microsoft.aspnet.signalr.client.transport.NegotiationException: There was a problem in the negotiation with the server
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.transport.HttpClientTransport$1.onResponse(HttpClientTransport.java:86)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.http.java.NetworkRunnable.run(NetworkRunnable.java:82)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ Caused by: java.lang.NoClassDefFoundError: microsoft.aspnet.signalr.client.transport.WebsocketTransport$1
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.transport.WebsocketTransport.start(WebsocketTransport.java:92)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.transport.AutomaticTransport.resolveTransport(AutomaticTransport.java:89)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.transport.AutomaticTransport.start(AutomaticTransport.java:143)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.Connection.startTransport(Connection.java:673)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.Connection.access$500(Connection.java:30)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.Connection$3.run(Connection.java:373)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.Connection$3.run(Connection.java:350)
05-27 09:10:39.855  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.SignalRFuture.setResult(SignalRFuture.java:73)
05-27 09:10:39.856  22247-22247/nl.vict.chatapp W/System.err﹕ at microsoft.aspnet.signalr.client.transport.HttpClientTransport$1.onResponse(HttpClientTransport.java:82)
05-27 09:10:39.856  22247-22247/nl.vict.chatapp W/System.err﹕ ... 2 more

Here is my code:

Hub:

public class ChatHub : Hub
    {
        public void Send(string name, string message)
        {
            Clients.All.addNewMessageToPage(name, message);
        }
    }

Main Activity (Android Studio)

ListView listView;
    HubConnection connection;
    HubProxy proxy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView)findViewById(R.id.listView);

        String[] values = new String[]{
                "Testvalue1",
                "Testvalue2",
                "Testvalue3"
        };

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,android.R.id.text1,values);

        listView.setAdapter(adapter);

        connection = new HubConnection("http://www.voffice.nl/chat");
        proxy = connection.createHubProxy("chatHub");
        SignalRFuture<Void> awaitConnection = connection.start();
        try{
            awaitConnection.get();
        }catch (InterruptedException e){
            e.printStackTrace();
        }catch (ExecutionException e){
            e.printStackTrace();
        }



    }

Thanks in Advance,

Kevin

--

EDIT:

I've checked the server and websockets are enabled.

like image 639
djkevino Avatar asked May 27 '15 09:05

djkevino


1 Answers

Here is how I got it working after few days of struggle:

  1. Download https://github.com/TooTallNate/Java-WebSocket and build it.

  2. Download https://github.com/SignalR/java-client,

  3. add libs folder to signalr-client-sdk and put java_websocket.jar that you built earlier
  4. Replace in signalr-client-sdk/build.gradle

    compile 'org.java-websocket:java-websocket:1.3.1'

    with:

    compile files('libs/java_websocket.jar')

  5. Go here and find fix for http:// to ws:// url https://github.com/SignalR/java-client/issues/63, change it in code

  6. Build signalr client and include it in your project, you also have to include java_websocket.jar that you built in first step, so your gradle file witll look like:

    compile 'client.signalr.aspnet.microsoft.signalr_client_sdk_android:signalr-client-sdk-android-release:1.0.0@aar' compile files('libs/signalr-client-sdk.jar') compile files('libs/java_websocket.jar')

Don't pass any querystring to HubConnection or it will hang!!

If you need to pass headers (like authorization token) you have to fix some more code, there is pull request for this: https://github.com/SignalR/java-client/pull/64

like image 151
formatc Avatar answered Oct 31 '22 06:10

formatc