sendAndWait method
will send a message to the socket, and will reply with a future that resolves to the next message received on the socket.
NOTE: This function will automatically append the terminator bytes if they have been specified.
Implementation
Future<TcpMessage?> sendAndWait(Object msg, {appendTerminator = true}) async {
// wait for the previous completer to complete or fail
await _completer?.future;
_completer = Completer<Uint8List?>();
send(msg, appendTerminator: appendTerminator);
var res = await _completer!.future.timeout(timeout, onTimeout: () {
return null;
});
if (res == null) return null;
return TcpMessage(res);
}