connectToServer method
Connects to the specified server.
Specify isSecure if you do not want to connect to a secure service.
Specify timeout to specify a different timeout for the connection.
This defaults to 20 seconds.
Implementation
Future<ConnectionInfo> connectToServer(
String host,
int port, {
bool isSecure = true,
Duration timeout = const Duration(seconds: 20),
}) async {
logApp(
'connecting to server $host:$port - '
'secure: $isSecure, timeout: $timeout',
);
connectionInfo = ConnectionInfo(host, port, isSecure: isSecure);
final socket = isSecure
? await SecureSocket.connect(
host,
port,
onBadCertificate: onBadCertificate,
).timeout(timeout)
: await Socket.connect(host, port).timeout(timeout);
_greetingsCompleter = Completer<ConnectionInfo>();
_isServerGreetingDone = false;
connect(socket);
return _greetingsCompleter.future;
}