connect method

  1. @override
Future<MqttClientConnectionStatus> connect (
  1. String server,
  2. int port
)
override

Connect - overridden

Implementation

@override
Future<MqttClientConnectionStatus> connect(String server, int port) {
  final completer = Completer<MqttClientConnectionStatus>();
  try {
    // Connect and save the socket.
    Socket.connect(server, port).then((dynamic socket) {
      client = socket;
      readWrapper = ReadWrapper();
      messageStream = MqttByteBuffer(typed.Uint8Buffer());
      _startListening();
      completer.complete();
    }).catchError((dynamic e) {
      onError(e);
      completer.completeError(e);
    });
  } on Exception catch (e) {
    completer.completeError(e);
    final message = 'MqttNormalConnection::The connection to the message '
        'broker {$server}:{$port} could not be made.';
    throw NoConnectionException(message);
  }
  return completer.future;
}