Notification<Void> result = rxClient.connect()
.flatMap(new Func1<ObservableConnection<TextWebSocketFrame, TextWebSocketFrame>, Observable<Void>>() {
@Override
public Observable<Void> call(final ObservableConnection<TextWebSocketFrame, TextWebSocketFrame> connection) {
return Observable.concat(
connection.writeAndFlush(new TextWebSocketFrame("Hello!!!")),
connection.getInput().take(noOfEvents).flatMap(new Func1<TextWebSocketFrame, Observable<Void>>() {
@Override
public Observable<Void> call(TextWebSocketFrame webSocketFrame) {
System.out.println("Got back: " + webSocketFrame.text());
return Observable.timer(interval, TimeUnit.MILLISECONDS)
.flatMap(new Func1<Long, Observable<Void>>() {
@Override
public Observable<Void> call(Long aLong) {
return connection.writeAndFlush(new TextWebSocketFrame("Hello!!!"));
}
});
}
}));
}