Pusher pusher = new Pusher(app key);
String socketId = pusher.getConnection().getSocketId();
尝试连接到推送器时socketId
为空。
Pusher客户端用于进行websocket调用的uri是
ws://ws.pusherapp.com:80/app/{app Key}?client=java-client&protocol=5&version=0.3.3
这会返回NULL
套接字ID
但是,如果我使用相同的URI使用测试客户端建立Websocket连接,我会得到一个有效的socketId。我做错了什么?
答案 0 :(得分:1)
在建立连接之前,不会设置socketId。请在此处查看onConnectionStateChange接口方法: https://github.com/pusher/pusher-websocket-java#api-overview
这是为获取socketId而专门更新的代码:
// Create a new Pusher instance
Pusher pusher = new Pusher(YOUR_APP_KEY);
pusher.connect(new ConnectionEventListener() {
@Override
public void onConnectionStateChange(ConnectionStateChange change) {
String socketId = pusher.getConnection().getSocketId();
System.out.printLn("The socketId is: " + socketId);
}
@Override
public void onError(String message, String code, Exception e) {
System.out.println("There was a problem connecting!");
}
}, ConnectionState.Connected);