EventLoop.createConnection

Create a streaming transport connection to a given Internet host and port: socket family $(D_PSYMBOL AddressFamily.INET) or $(D_PSYMBOL AddressFamily.INET6) depending on host (or family if specified), socket type $(D_PSYMBOL SocketType.STREAM).

This method is a coroutine which will try to establish the connection in the background. When successful, the coroutine returns a (transport, protocol) tuple.

The chronological synopsis of the underlying operation is as follows:

The connection is established, and a transport is created to represent it. $(D_PSYMBOL protocolFactory) is called without arguments and must return a protocol instance. The protocol instance is tied to the transport, and its $(D_PSYMBOL connectionMade()) method is called. The coroutine returns successfully with the $(D_PSYMBOL (transport, protocol)) tuple.

The created transport is an implementation-dependent bidirectional stream.

Options allowing to change how the connection is created:

class EventLoop
createConnection
(,
in char[] host = null
,
in char[] service = null
,,
AddressFamily addressFamily = UNSPECIFIED!AddressFamily
,
ProtocolType protocolType = UNSPECIFIED!ProtocolType
,
AddressInfoFlags addressInfoFlags = UNSPECIFIED!AddressInfoFlags
,
Socket socket = null
,
in char[] localHost = null
,
in char[] localService = null
,
in char[] serverHostname = null
)

Parameters

protocolFactory ProtocolFactory

is a callable returning a protocol instance

host char[]

if empty then the $(D_PSYMBOL socket) parameter should be specified.

service char[]

service name or port number.

sslContext SslContext

if not $(D_KEYWORD null), a SSL/TLS transport is created (by default a plain TCP transport is created).

serverHostname char[]

is only for use together with ssl, and sets or overrides the hostname that the target server’s certificate will be matched against. By default the value of the host argument is used. If host is empty, there is no default and you must pass a value for $(D_PSYMBOL serverHostname). If $(D_PSYMBOL serverHostname) is empty, hostname matching is disabled (which is a serious security risk, allowing for man-in-the-middle-attacks).

addressFamily AddressFamily

optional adress family.

protocolType ProtocolType

optional protocol.

addressInfoFlags AddressInfoFlags

optional flags.

socket Socket

if not $(D_KEYWORD null), should be an existing, already connected $(D_PSYMBOL Socket) object to be used by the transport. If $(D_PSYMBOL socket) is given, none of $(D_PSYMBOL host), $(D_PSYMBOL service), $(D_PSYMBOL addressFamily), $(D_PSYMBOL protocolType), $(D_PSYMBOL addressInfoFlags) and $(D_PSYMBOL localAddress) should be specified.

localHost char[]

if given, together with $(D_PSYMBOL localService) is used to bind the socket locally. The $(D_PSYMBOL localHost) and $(D_PSYMBOL localService) are looked up using $(D_PSYMBOL getAddressInfo()), similarly to host and service.

localService char[]

see $(D_PSYMBOL localHost).

Return Value

Type: auto

Tuple!(Transport, "transport", Protocol, "protocol")

Meta