Search in sources :

Example 6 with TcpClient

use of reactor.netty.tcp.TcpClient in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    TcpClient tcpClient = TcpClient.create().host("example.com").port(80).handle((inbound, outbound) -> outbound.sendString(Mono.just("hello")));
    // <1>
    tcpClient.warmup().block();
    // <2>
    Connection connection = tcpClient.connectNow();
    connection.onDispose().block();
}
Also used : TcpClient(reactor.netty.tcp.TcpClient) Connection(reactor.netty.Connection)

Example 7 with TcpClient

use of reactor.netty.tcp.TcpClient in project reactor-netty by reactor.

the class DiscardClient method main.

public static void main(String[] args) {
    TcpClient client = TcpClient.create().port(PORT).wiretap(WIRETAP);
    if (SECURE) {
        TcpSslContextSpec tcpSslContextSpec = TcpSslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
        client = client.secure(spec -> spec.sslContext(tcpSslContextSpec));
    }
    Connection connection = client.handle((in, out) -> {
        // Discards the incoming data and releases the buffers
        in.receive().subscribe();
        return out.sendString(Flux.interval(Duration.ofMillis(100)).map(l -> l + ""));
    }).connectNow();
    connection.onDispose().block();
}
Also used : TcpClient(reactor.netty.tcp.TcpClient) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) Flux(reactor.core.publisher.Flux) TcpSslContextSpec(reactor.netty.tcp.TcpSslContextSpec) Duration(java.time.Duration) Connection(reactor.netty.Connection) TcpClient(reactor.netty.tcp.TcpClient) Connection(reactor.netty.Connection) TcpSslContextSpec(reactor.netty.tcp.TcpSslContextSpec)

Example 8 with TcpClient

use of reactor.netty.tcp.TcpClient in project reactor-netty by reactor.

the class EchoClient method main.

public static void main(String[] args) {
    TcpClient client = TcpClient.create().port(PORT).wiretap(WIRETAP);
    if (SECURE) {
        TcpSslContextSpec tcpSslContextSpec = TcpSslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
        client = client.secure(spec -> spec.sslContext(tcpSslContextSpec));
    }
    Connection connection = client.handle((in, out) -> out.send(Flux.concat(ByteBufFlux.fromString(Mono.just("echo")), in.receive().retain()))).connectNow();
    connection.onDispose().block();
}
Also used : TcpClient(reactor.netty.tcp.TcpClient) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) Flux(reactor.core.publisher.Flux) ByteBufFlux(reactor.netty.ByteBufFlux) TcpSslContextSpec(reactor.netty.tcp.TcpSslContextSpec) Mono(reactor.core.publisher.Mono) Connection(reactor.netty.Connection) TcpClient(reactor.netty.tcp.TcpClient) Connection(reactor.netty.Connection) TcpSslContextSpec(reactor.netty.tcp.TcpSslContextSpec)

Aggregations

TcpClient (reactor.netty.tcp.TcpClient)8 Connection (reactor.netty.Connection)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 SslContext (io.netty.handler.ssl.SslContext)2 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)2 Duration (java.time.Duration)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.jupiter.api.Test)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2 TcpSslContextSpec (reactor.netty.tcp.TcpSslContextSpec)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 ByteBufHolder (io.netty.buffer.ByteBufHolder)1 Unpooled (io.netty.buffer.Unpooled)1 Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelOption (io.netty.channel.ChannelOption)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1