connect static method
creates a TcpClient and immediately attempts to connect. If successful or if the requested connection should manage reconnecting on it's own, the client will complete the future. Otherwise, an exception will be thrown.
Implementation
static Future<TcpClient> connect(
String host,
int port, {
String? terminatorString,
List<int>? terminatorBytes,
TcpConnectionType connectionType = TcpConnectionType.untilClosed,
Duration timeout = const Duration(seconds: 2),
}) async {
Uint8List? tb;
if (terminatorString != null) terminatorBytes ??= Uint8List.fromList(utf8.encode(terminatorString));
if (terminatorBytes != null) tb = Uint8List.fromList(terminatorBytes);
var c = TcpClient(host, port, timeout: timeout, terminatorBytes: tb);
if (connectionType == TcpConnectionType.persistent) {
await c._connectPersistent();
} else if (!await c._connect()) {
throw TcpNotReady('Failed connecting to $host:$port');
}
return c;
}