NIOClientTCPBootstrapProtocol

public protocol NIOClientTCPBootstrapProtocol

NIOClientTCPBootstrapProtocol is implemented by various underlying transport mechanisms. Typically, this will be the BSD Sockets API implemented by ClientBootstrap.

  • Initialize the connected SocketChannel with initializer. The most common task in initializer is to add ChannelHandlers to the ChannelPipeline.

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

    Warning

    The handler closure may be invoked multiple times so it’s usually the right choice to instantiate ChannelHandlers within handler. The reason handler may be invoked multiple times is that to successfully set up a connection multiple connections might be setup in the process. Assuming a hostname that resolves to both IPv4 and IPv6 addresses, NIO will follow Happy Eyeballs and race both an IPv4 and an IPv6 connection. It is possible that both connections get fully established before the IPv4 connection will be closed again because the IPv6 connection ‘won the race’. Therefore the channelInitializer might be called multiple times and it’s important not to share stateful ChannelHandlers in more than one Channel.

    Declaration

    Swift

    func channelInitializer(_ handler: @escaping (Channel) -> EventLoopFuture<Void>) -> Self

    Parameters

    handler

    A closure that initializes the provided Channel.

  • Sets the protocol handlers that will be added to the front of the ChannelPipeline right after the channelInitializer has been called.

    Per bootstrap, you can only set the protocolHandlers once. Typically, protocolHandlers are used for the TLS implementation. Most notably, NIOClientTCPBootstrap, NIO’s “universal bootstrap” abstraction, uses protocolHandlers to add the required ChannelHandlers for many TLS implementations.

    Declaration

    Swift

    func protocolHandlers(_ handlers: @escaping () -> [ChannelHandler]) -> Self
  • Specifies a ChannelOption to be applied to the SocketChannel.

    Declaration

    Swift

    func channelOption<Option>(_ option: Option, value: Option.Value) -> Self where Option : ChannelOption

    Parameters

    option

    The option to be applied.

    value

    The value for the option.

  • _applyChannelConvenienceOptions(_:) Default implementation

    Apply any understood convenience options to the bootstrap, removing them from the set of options if they are consumed. Method is optional to implement and should never be directly called by users.

    Default Implementation

    Apply any understood convenience options to the bootstrap, removing them from the set of options if they are consumed.

    Declaration

    Swift

    func _applyChannelConvenienceOptions(_ options: inout ChannelOptions.TCPConvenienceOptions) -> Self

    Parameters

    options

    The options to try applying - the options applied should be consumed from here.

    Return Value

    The updated bootstrap with and options applied.

  • Declaration

    Swift

    func connectTimeout(_ timeout: TimeAmount) -> Self

    Parameters

    timeout

    The timeout that will apply to the connection attempt.

  • Specify the host and port to connect to for the TCP Channel that will be established.

    Declaration

    Swift

    func connect(host: String, port: Int) -> EventLoopFuture<Channel>

    Parameters

    host

    The host to connect to.

    port

    The port to connect to.

    Return Value

    An EventLoopFuture<Channel> to deliver the Channel when connected.

  • Specify the address to connect to for the TCP Channel that will be established.

    Declaration

    Swift

    func connect(to address: SocketAddress) -> EventLoopFuture<Channel>

    Parameters

    address

    The address to connect to.

    Return Value

    An EventLoopFuture<Channel> to deliver the Channel when connected.

  • Specify the unixDomainSocket path to connect to for the UDS Channel that will be established.

    Declaration

    Swift

    func connect(unixDomainSocketPath: String) -> EventLoopFuture<Channel>

    Parameters

    unixDomainSocketPath

    The Unix domain socket path to connect to.

    Return Value

    An EventLoopFuture<Channel> to deliver the Channel when connected.