Skip to content

Instantly share code, notes, and snippets.

@NiteshKant
Created February 25, 2015 06:15
Show Gist options
  • Save NiteshKant/d5276c0fcf352d79da5c to your computer and use it in GitHub Desktop.
Save NiteshKant/d5276c0fcf352d79da5c to your computer and use it in GitHub Desktop.
How to connect a client response to a server response.
package io.reactivex.netty.examples.http;
import io.netty.buffer.ByteBuf;
import io.netty.handler.logging.LogLevel;
import io.reactivex.netty.RxNetty;
import io.reactivex.netty.protocol.http.client.HttpClientRequest;
import io.reactivex.netty.protocol.http.client.HttpClientResponse;
import io.reactivex.netty.protocol.http.server.HttpServerPipelineConfigurator;
import io.reactivex.netty.protocol.http.server.HttpServerRequest;
import io.reactivex.netty.protocol.http.server.HttpServerResponse;
import io.reactivex.netty.protocol.http.server.RequestHandler;
import io.reactivex.netty.protocol.http.sse.ServerSentEventEncoder;
import rx.Observable;
import rx.functions.Func1;
import java.util.concurrent.TimeUnit;
public class ClientToServer {
public static void main(String[] args) {
RxNetty.createHttpServer(8999, (req, resp) -> resp.writeStringAndFlush("Hello")).start();
RxNetty.createHttpServer(9099,
(request, response) -> RxNetty.createHttpGet("http://127.0.0.1:8999/hello")
.flatMap(resp -> {
response.setStatus(resp.getStatus());
return resp.getContent()
.map(ByteBuf::retain)
.flatMap(response::writeAndFlush);
}))
.startAndWait();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment