Search in sources :

Example 11 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    Connection connection = TcpClient.create().host("example.com").port(80).doOnConnected(conn -> conn.addHandler(new ReadTimeoutHandler(10, TimeUnit.SECONDS))).doOnChannelInit((observer, channel, remoteAddress) -> channel.pipeline().addFirst(// <2>
    new LoggingHandler("reactor.netty.examples"))).connectNow();
    connection.onDispose().block();
}
Also used : TcpClient(reactor.netty.tcp.TcpClient) TimeUnit(java.util.concurrent.TimeUnit) LoggingHandler(io.netty.handler.logging.LoggingHandler) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) Connection(reactor.netty.Connection) LoggingHandler(io.netty.handler.logging.LoggingHandler) Connection(reactor.netty.Connection) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler)

Example 12 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    ConnectionProvider provider = ConnectionProvider.builder("fixed").maxConnections(50).pendingAcquireTimeout(// <1>
    Duration.ofSeconds(60)).build();
    Connection connection = TcpClient.create(provider).host("example.com").port(80).connectNow();
    connection.onDispose().block();
}
Also used : Connection(reactor.netty.Connection) ConnectionProvider(reactor.netty.resources.ConnectionProvider)

Example 13 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    Connection connection = TcpClient.create().host("example.com").port(80).proxy(spec -> spec.type(ProxyProvider.Proxy.SOCKS4).host("proxy").port(8080).nonProxyHosts("localhost").connectTimeoutMillis(// <1>
    20_000)).connectNow();
    connection.onDispose().block();
}
Also used : TcpClient(reactor.netty.tcp.TcpClient) ProxyProvider(reactor.netty.transport.ProxyProvider) Connection(reactor.netty.Connection) Connection(reactor.netty.Connection)

Example 14 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    Connection connection = UdpClient.create().bindAddress(Application::newDomainSocketAddress).remoteAddress(// <1>
    () -> new DomainSocketAddress("/tmp/test-server.sock")).handle((in, out) -> out.sendString(Mono.just("hello")).then(in.receive().asString().doOnNext(System.out::println).then())).connectNow();
    connection.onDispose().block();
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) UdpClient(reactor.netty.udp.UdpClient) Mono(reactor.core.publisher.Mono) Connection(reactor.netty.Connection) File(java.io.File) Connection(reactor.netty.Connection) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Example 15 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    Connection connection = UdpClient.create().host(// <1>
    "example.com").port(// <2>
    80).connectNow(Duration.ofSeconds(30));
    connection.onDispose().block();
}
Also used : Connection(reactor.netty.Connection)

Aggregations

Connection (reactor.netty.Connection)137 Test (org.junit.jupiter.api.Test)69 CountDownLatch (java.util.concurrent.CountDownLatch)52 Duration (java.time.Duration)49 Mono (reactor.core.publisher.Mono)47 InetSocketAddress (java.net.InetSocketAddress)41 TimeUnit (java.util.concurrent.TimeUnit)39 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)38 LoopResources (reactor.netty.resources.LoopResources)38 ByteBuf (io.netty.buffer.ByteBuf)35 Flux (reactor.core.publisher.Flux)35 DisposableServer (reactor.netty.DisposableServer)35 DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)33 AtomicReference (java.util.concurrent.atomic.AtomicReference)32 List (java.util.List)31 IOException (java.io.IOException)30 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)30 ChannelOption (io.netty.channel.ChannelOption)29 Unpooled (io.netty.buffer.Unpooled)28 Charset (java.nio.charset.Charset)28