DatagramBootstrap
A DatagramBootstrap
is an easy way to bootstrap a DatagramChannel
when creating datagram clients and servers.
final class DatagramBootstrap
Example:
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
try! group.syncShutdownGracefully()
}
let bootstrap = DatagramBootstrap(group: group)
// Enable SO_REUSEADDR.
.channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
.channelInitializer { channel in
channel.pipeline.addHandler(MyChannelHandler())
}
let channel = try! bootstrap.bind(host: "127.0.0.1", port: 53).wait()
/* the Channel is now ready to send/receive datagrams */
try channel.closeFuture.wait() // Wait until the channel un-binds.
The DatagramChannel
will operate on AddressedEnvelope<ByteBuffer>
as inbound and outbound messages.