onConnectCallback在使用Autobahn-java进行WAMP连接时不调用

时间:2017-09-01 05:22:02

标签: java android autobahn

我正在使用此代码(如Autobahn演示的ExampleClient中所示)连接客户端:

    ExecutorService executor = Executors.newSingleThreadExecutor();
    session = new Session(executor);
    session.addOnConnectListener(this);
    session.addOnJoinListener(this);
    session.addOnLeaveListener(this);
    session.addOnDisconnectListener(this);

    // Now create a transport list to try and add transports to it.
    // In our case, we currently only have Netty based WAMP-over-WebSocket.
    List<ITransport> transports = new ArrayList<>();
    transports.add(new NettyTransport("wss://xxxxxxx.com/wss2/", executor));

    // Now provide a list of authentication methods.
    // We only support anonymous auth currently.
    List<IAuthenticator> authenticators = new ArrayList<>();
    authenticators.add(new AnonymousAuth());

    // finally, provide everything to a Client instance and connect
    Client client = new Client(transports, executor);
    client.add(session, mLiveStream.streamName, authenticators);
    client.connect();

但是onConnect回调永远不会被调用。

1 个答案:

答案 0 :(得分:0)

你应该设置功能名称, 改变:

ExecutorService executor = Executors.newSingleThreadExecutor();
session = new Session(executor);
session.addOnConnectListener(this);
session.addOnJoinListener(this);
session.addOnLeaveListener(this);
session.addOnDisconnectListener(this);

到:

ExecutorService executor = Executors.newSingleThreadExecutor();
session = new Session(executor);
session.addOnConnectListener(this::functionName);
session.addOnJoinListener(this::functionName2);
session.addOnLeaveListener(this::functionName3);
session.addOnDisconnectListener(this::functionName4);

参考readme