我正在尝试将Android应用与服务器套接字连接,但是当我不知道如何订阅群组时。我正在使用WebSocketClient(import org.java_websocket.client.WebSocketClient;),并且当它连接时我收到一条消息。
下一步是订阅一个组以接收一个或另一个信息,但我不能这样做。我希望你能帮助我。
谢谢!
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
e.printStackTrace();
return;
}
mWebSocketClient = new WebSocketClient(uri) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
Toast.makeText(ShowParking.this, "OPEN", Toast.LENGTH_SHORT).show();
}
@Override
public void onMessage(String s) {
final String message = s;
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ShowParking.this, message, Toast.LENGTH_SHORT).show();
Toast.makeText(ShowParking.this, mWebSocketClient.getReadyState().toString(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onClose(int i, String s, boolean b) {
Toast.makeText(ShowParking.this, "CLOSE", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Exception e) {
}
};
mWebSocketClient.connect();
Toast.makeText(ShowParking.this, "CONECTO", Toast.LENGTH_SHORT).show();