webflux tcp client code example

Example 1: webflux tcp client examples

import reactor.netty.Connection;
import reactor.netty.tcp.TcpClient;

public class Application {

    public static void main(String[] args) {
        Connection connection =
                TcpClient.create()
                         .host("example.com") (1)
                         .port(80)            (2)
                         .connectNow();

        connection.onDispose()
                  .block();
    }
}

Example 2: webflux tcp client examples

import reactor.core.publisher.Mono;
import reactor.netty.Connection;
import reactor.netty.tcp.TcpClient;

public class Application {

    public static void main(String[] args) {
        Connection connection =
                TcpClient.create()
                         .host("example.com")
                         .port(80)
                         .handle((inbound, outbound) -> outbound.sendString(Mono.just("hello"))) (1)
                         .connectNow();

        connection.onDispose()
                  .block();
    }
}