1

我使用下面的代码连接集线器。

它的工作正常。但有时突然协商GET方法调用了数千次。

private HubConnection createLocalHubConnection() {
    if (Common.isInternetAvailable(CallObserverTestService.this)) {
        Log.i(TAG, "Create Connection");
        final HubConnection loConnection = new HubConnection(WebService.getHubURL(CallObserverTestService.this));
        Log.i(TAG, "Connection State1: " + loConnection.getState());
        if (loConnection.getState() == ConnectionState.Disconnected) {
            moProxy = loConnection.createHubProxy(CallObserverTestService.this.getString(R.string.hub));
            try {
                loConnection.stop();
                loConnection.start().done(new Action<Void>() {
                    @Override
                    public void run(Void obj) throws Exception {
                        Log.i(TAG, "Connection URL: " + loConnection.getUrl());
                        Log.i(TAG, "SignalR ConnectionId: " + loConnection.getConnectionId());
                    }
                }).onError(new ErrorCallback() {
                    @Override
                    public void onError(Throwable error) {
                        Log.i(TAG, "SignalR: onError : " + error.getMessage());
                        error.printStackTrace();
                        Log.logException(TAG, error);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                Log.logException(TAG, e);
            }
        }
        return loConnection;
    }
    return null;
}

循环调用时错误如下

协商错误:与服务器协商出现问题

negotiate: https://MyDomain/signalr/negotiate?clientProtocol=1.3&connectionData=%5B%7B%22name%22%3A%22MyHubName%22%7D%5D

参考链接:https ://github.com/SignalR/java-client/tree/master/signalr-client-sdk

4

0 回答 0