open method
Implementation
Future<bool> open() async {
var ret = false;
if (_socket == null) {
List<String> ipport = _addr.split(":");
try {
int port = ipport.length == 2 ? int.parse(ipport[1]) : 9100;
InternetAddress host = (await InternetAddress.lookup(ipport[0])).first;
_socket = await Socket.connect(host, port,
timeout: const Duration(seconds: 5));
_socket!.listen((var data) => onReceive(utf8.decode(data)), onDone: () {
close();
}, onError: (e) {
onError(e);
close();
});
ret = true;
} catch (msg) {
onError("$msg");
}
}
return ret;
}