Search in sources :

Example 26 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 server = UdpServer.create().metrics(// <1>
    true).bindNow(Duration.ofSeconds(30));
    server.onDispose().block();
}
Also used : Connection(reactor.netty.Connection)

Example 27 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 server = UdpServer.create().handle((in, out) -> out.sendObject(in.receiveObject().map(o -> {
        if (o instanceof DatagramPacket) {
            DatagramPacket p = (DatagramPacket) o;
            // <1>
            return new DatagramPacket(p.content().retain(), p.sender());
        } else {
            return Mono.error(new Exception("Unexpected type of the message: " + o));
        }
    }))).bindNow(Duration.ofSeconds(30));
    server.onDispose().block();
}
Also used : Duration(java.time.Duration) DatagramPacket(io.netty.channel.socket.DatagramPacket) Mono(reactor.core.publisher.Mono) Connection(reactor.netty.Connection) UdpServer(reactor.netty.udp.UdpServer) DatagramPacket(io.netty.channel.socket.DatagramPacket) Connection(reactor.netty.Connection)

Example 28 with Connection

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

the class Application method main.

public static void main(String[] args) {
    LoopResources loop = LoopResources.create("event-loop", 1, 4, true);
    Connection connection = TcpClient.create().host("example.com").port(80).runOn(loop).connectNow();
    connection.onDispose().block();
}
Also used : LoopResources(reactor.netty.resources.LoopResources) Connection(reactor.netty.Connection)

Example 29 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).metrics(// <1>
    true).connectNow();
    connection.onDispose().block();
}
Also used : Connection(reactor.netty.Connection)

Example 30 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.newConnection().host("example.com").port(80).connectNow();
    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