gpt4 book ai didi

java - Signal R native Android 应用程序协商失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:47 25 4
gpt4 key购买 nike

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

它只是一个基本的 Hub 文件,我想用它来测试一些东西,但到目前为止我没有运气。有人可以看看我做错了什么吗?每次我尝试运行它时,我都会得到以下 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

这是我的代码:

中心:

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

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



}

提前致谢

凯文

--

编辑:

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

最佳答案

经过几天的努力,我是这样工作的:

  1. 下载https://github.com/TooTallNate/Java-WebSocket并构建它。

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

  3. 将 libs 文件夹添加到 signalr-client-sdk 并放入 java_websocket.jar你之前 build 的
  4. 在signalr-client-sdk/build.gradle中替换

    编译 'org.java-websocket:java-websocket:1.3.1'

    与:

    编译文件('libs/java_websocket.jar')

  5. 到这里找到 http://到 ws://url https://github.com/SignalR/java-client/issues/63 的修复, 在代码中更改它

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

    编译'client.signalr.aspnet.microsoft.signalr_client_sdk_android:signalr-client-sdk-android-release:1.0.0@aar'
    编译文件('libs/signalr-client-sdk.jar')
    编译文件('libs/java_websocket.jar')

不要向 HubConnection 传递任何查询字符串,否则它将挂起!!

如果您需要传递 header (如授权 token ),则必须修复更多代码,为此有拉取请求:https://github.com/SignalR/java-client/pull/64

关于java - Signal R native Android 应用程序协商失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30478075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com