connect method
Connects to the Gatekeeper server.
addressType: If provided, resolves host to this IP family (InternetAddressType.IPv4 or InternetAddressType.IPv6) and connects to the resolved address, forcing the connection over that family. Ifnull(default), connects using the platform's default resolution.
Returns a Future that completes with true if the connection was successful,
or false if already connected.
Implementation
Future<bool> connect({InternetAddressType? addressType}) async {
if (isConnected) return false;
Socket socket;
if (addressType != null) {
var addresses = await InternetAddress.lookup(host, type: addressType);
if (addresses.isEmpty) {
throw SocketException("No $addressType address for host `$host`",
address: null);
}
socket = await Socket.connect(addresses.first, port);
} else {
socket = await Socket.connect(host, port);
}
_socket = socket;
socket.listen(_onData, cancelOnError: true, onDone: _onClose);
return true;
}