信号R本机Android应用协商失败

我正在尝试创build一个可以连接到我的基本SignalR Hub的Android应用程序。

它只是一个基本的Hub文件,我想testing的东西,但我迄今没有运气。 有人可以看看我做错了什么吗? 每次我尝试运行它,我得到以下堆栈:

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 

这是我的代码:

枢纽:

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

主要活动(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(); } } 

提前致谢,

凯文

编辑:

我已经检查了服务器和websockets启用。

Solutions Collecting From Web of "信号R本机Android应用协商失败"

下面是我经过几天的斗争之后如何运作的:

  1. 下载https://github.com/TooTallNate/Java-WebSocket并build立它&#x3002;

  2. 下载https://github.com/SignalR/java-client

  3. 将libs文件夹添加到signalr-client-sdk中,并放入java_websocket.jar构build的java_websocket.jar
  4. 在signalr-client-sdk / build.gradle中replace

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

    有:

    compile files('libs/java_websocket.jar')

  5. 去这里findhttp://到ws:// url https://github.com/SignalR/java-client/issues/63的修正,在代码中修改&#x5B83;

  6. 构buildsignalr客户端并将其包含在您的项目中,还必须包含您在第一步中构build的java_websocket.jar,以便您的gradle文件如下所示:

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

不要将任何querystring传递给HubConnection,否则会挂起!

如果你需要传递头文件(比如授权令牌),你必须修改更多的代码,这里有一个pull请求: https : //github.com/SignalR/java-client/pull/64