Search in sources :

Example 1 with UdpServer

use of reactor.netty.udp.UdpServer in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    UdpServer udpServer = UdpServer.create().handle((in, out) -> out.sendObject(in.receiveObject().map(o -> {
        if (o instanceof DatagramPacket) {
            DatagramPacket p = (DatagramPacket) o;
            return new DatagramPacket(p.content().retain(), p.sender());
        } else {
            return Mono.error(new Exception("Unexpected type of the message: " + o));
        }
    })));
    // <1>
    udpServer.warmup().block();
    Connection server = udpServer.bindNow(Duration.ofSeconds(30));
    server.onDispose().block();
}
Also used : DatagramPacket(io.netty.channel.socket.DatagramPacket) Connection(reactor.netty.Connection) UdpServer(reactor.netty.udp.UdpServer)

Aggregations

DatagramPacket (io.netty.channel.socket.DatagramPacket)1 Connection (reactor.netty.Connection)1 UdpServer (reactor.netty.udp.UdpServer)1