Signal R Aplicativo nativo para Android Negociação falhou

9

Estou tentando criar um aplicativo para Android que possa se conectar ao meu Hub SignalR básico.

É apenas um arquivo Hub básico que eu quero testar, mas até agora não tive sorte. Alguém poderia dar uma olhada na (s) coisa (s) que estou fazendo errado? Toda vez que tento executá-lo, recebo as seguintes características:

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

Aqui está o meu código:

Hub:

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

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



    }

Obrigado antecipadamente,

Kevin

-

EDITAR:

Eu verifiquei o servidor e os websockets estão ativados.

    
por djkevino 27.05.2015 в 11:15
fonte

1 resposta

2

Veja como eu consegui trabalhar depois de alguns dias de luta:

  1. Faça o download do link e construa-o.

  2. Faça o download do link ,

  3. adicione a pasta libs ao signalr-client-sdk e coloque java_websocket.jar que você construiu anteriormente
  4. Substitua em signalr-client-sdk / build.gradle

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

    com:

    compile files('libs/java_websocket.jar')

  5. Acesse aqui e encontre a correção para http: // para ws: // url link , mude-o no código

  6. Construa o cliente signalr e inclua-o em seu projeto, você também tem que incluir java_websocket.jar que você construiu na primeira etapa, assim seu arquivo gradle se parecerá com:

    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')

Não passe nenhuma querystring para o HubConnection ou ele será interrompido !!

Se você precisar passar cabeçalhos (como token de autorização) você precisa corrigir mais um código, há um pedido de pull para isso: link

    
por formatc 14.06.2015 / 18:39
fonte