connect method
Connect
Implementation
@override
Future<MqttConnectionStatus?> connect(String server, int port) {
final completer = Completer<MqttConnectionStatus?>();
MqttLogger.log('MqttNormalConnection::connect- entered');
try {
// Connect and save the socket.
Socket.connect(server, port).then((dynamic socket) {
// Socket options
final applied = _applySocketOptions(socket, socketOptions);
if (applied) {
MqttLogger.log(
'MqttNormalConnection::connect - socket options applied');
}
client = socket;
_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 MqttNoConnectionException(message);
}
return completer.future;
}