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
withinitializer
. The most common task in initializer is to addChannelHandler
s to theChannelPipeline
.The connected
Channel
will operate onByteBuffer
as inbound andIOData
as outbound messages.Warning
The
handler
closure may be invoked multiple times so it’s usually the right choice to instantiateChannelHandler
s withinhandler
. The reasonhandler
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 thechannelInitializer
might be called multiple times and it’s important not to share statefulChannelHandler
s in more than oneChannel
.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 thechannelInitializer
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, usesprotocolHandlers
to add the requiredChannelHandler
s for many TLS implementations.Declaration
Swift
func protocolHandlers(_ handlers: @escaping () -> [ChannelHandler]) -> Self
-
Specifies a
ChannelOption
to be applied to theSocketChannel
.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
andport
to connect to for the TCPChannel
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 theChannel
when connected. -
Specify the
address
to connect to for the TCPChannel
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 theChannel
when connected. -
Specify the
unixDomainSocket
path to connect to for the UDSChannel
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 theChannel
when connected.