@Override public Optional<ServerTransport> buildServer(URI uri) { Objects.requireNonNull(uri, "uri must not be null"); if (!SCHEME.equals(uri.getScheme())) { return Optional.empty(); } return Optional.of( TcpServerTransport.create(TcpServer.create().host(uri.getHost()).port(uri.getPort()))); } }
/** * Creates a new instance binding to localhost * * @param port the port to bind to * @return a new instance */ public static TcpServerTransport create(int port) { TcpServer server = TcpServer.create().port(port); return create(server); }
/** * Creates a new instance * * @param bindAddress the address to bind to * @param port the port to bind to * @return a new instance * @throws NullPointerException if {@code bindAddress} is {@code null} */ public static TcpServerTransport create(String bindAddress, int port) { Objects.requireNonNull(bindAddress, "bindAddress must not be null"); TcpServer server = TcpServer.create().host(bindAddress).port(port); return create(server); }
/** * The port to which this server should bind. * * @param port The port to bind to. * * @return a new {@link HttpServer} */ public final HttpServer port(int port) { return tcpConfiguration(tcpServer -> tcpServer.port(port)); }
/** * The port to which this server should bind. * * @param port The port to bind to. * * @return a new {@link HttpServer} */ public final HttpServer port(int port) { return tcpConfiguration(tcpServer -> tcpServer.port(port)); }
@Override public Optional<ServerTransport> buildServer(URI uri) { Objects.requireNonNull(uri, "uri must not be null"); if (!SCHEME.equals(uri.getScheme())) { return Optional.empty(); } return Optional.of( TcpServerTransport.create(TcpServer.create().host(uri.getHost()).port(uri.getPort()))); } }
/** * Creates a new instance binding to localhost * * @param port the port to bind to * @return a new instance */ public static TcpServerTransport create(int port) { TcpServer server = TcpServer.create().port(port); return create(server); }
/** * Creates a new instance * * @param bindAddress the address to bind to * @param port the port to bind to * @return a new instance * @throws NullPointerException if {@code bindAddress} is {@code null} */ public static TcpServerTransport create(String bindAddress, int port) { Objects.requireNonNull(bindAddress, "bindAddress must not be null"); TcpServer server = TcpServer.create().host(bindAddress).port(port); return create(server); }
@Test public void gettingOptionsDuplicates() { TcpServer server = TcpServer.create().host("foo").port(123); Assertions.assertThat(server.configure()) .isNotSameAs(TcpServerBind.INSTANCE.serverBootstrap) .isNotSameAs(server.configure()); }
@Test public void testIssue462() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); DisposableServer server = TcpServer.create() .port(0) .handle((in, out) -> { in.receive() .log("channel") .subscribe(trip -> countDownLatch.countDown()); return Flux.never(); }) .wiretap(true) .bindNow(); assertNotNull(server); System.out.println("PORT +" + server.address() .getPort()); Connection client = TcpClient.create() .port(server.address() .getPort()) .handle((in, out) -> out.sendString(Flux.just("test"))) .wiretap(true) .connectNow(); assertNotNull(client); client.disposeNow(); server.disposeNow(); assertThat("Latch was counted down", countDownLatch.await(5, TimeUnit.SECONDS)); }
.port(port) .handle((in, out) -> { try {
@Test public void prematureCancel() { DirectProcessor<Void> signal = DirectProcessor.create(); DisposableServer x = TcpServer.create() .host("localhost") .port(0) .handle((in, out) -> { signal.onComplete(); return out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder())) .sendObject(Mono.delay(Duration.ofSeconds(2)) .map(t -> new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.PROCESSING))) .neverComplete(); }) .wiretap(true) .bindNow(Duration.ofSeconds(30)); StepVerifier.create( createHttpClientForContextWithAddress(x) .get() .uri("/") .responseContent() .timeout(signal)) .verifyError(TimeoutException.class); }
@Test public void exposesRemoteAddress() throws InterruptedException { final int port = SocketUtils.findAvailableTcpPort(); final CountDownLatch latch = new CountDownLatch(1); DisposableServer server = TcpServer.create() .port(port) .handle((in, out) -> { in.withConnection(c -> { InetSocketAddress addr = c.address(); assertNotNull("remote address is not null", addr.getAddress()); latch.countDown(); }); return Flux.never(); }) .wiretap(true) .bindNow(); assertNotNull(server); Connection client = TcpClient.create().port(port) .handle((in, out) -> out.sendString(Flux.just("Hello World!"))) .wiretap(true) .connectNow(); assertNotNull(client); assertTrue("Latch was counted down", latch.await(5, TimeUnit.SECONDS)); client.disposeNow(); server.disposeNow(); }
DisposableServer server = TcpServer.create() .port(0) .doOnConnection(c -> c.addHandlerLast("codec", new LineBasedFrameDecoder(256)))
DisposableServer x = TcpServer.create() .port(0) .handle((in, out) -> in.receive()
.doOnConnection(c -> c.addHandlerLast("codec", new LineBasedFrameDecoder(8 * 1024))) .port(port);
TcpServer.create() .host("localhost") .port(0) .handle((in, out) -> out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder()))