ClientBootstrap

public final class ClientBootstrap

A ClientBootstrap is an easy way to bootstrap a SocketChannel when creating network clients.

Usually you re-use a ClientBootstrap once you set it up and called connect multiple times on it. This way you ensure that the same EventLoops will be shared across all your connections.

Example:

    let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
    defer {
        try! group.syncShutdownGracefully()
    }
    let bootstrap = ClientBootstrap(group: group)
        // Enable SO_REUSEADDR.
        .channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
        .channelInitializer { channel in
            // always instantiate the handler _within_ the closure as
            // it may be called multiple times (for example if the hostname
            // resolves to both IPv4 and IPv6 addresses, cf. Happy Eyeballs).
            channel.pipeline.addHandler(MyChannelHandler())
        }
    try! bootstrap.connect(host: "example.org", port: 12345).wait()
    /* the Channel is now connected */

The connected SocketChannel will operate on ByteBuffer as inbound and on IOData as outbound messages.