我正在使用此代码(如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回调永远不会被调用。
答案 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