Line data Source code
1 : /*
2 : * Package : mqtt_client
3 : * Author : S. Hamblett <steve.hamblett@linux.com>
4 : * Date : 22/06/2017
5 : * Copyright : S.Hamblett
6 : */
7 :
8 : part of mqtt_client;
9 :
10 : /// The MQTT normal(insecure TCP) connection class
11 : class MqttNormalConnection extends MqttConnection {
12 :
13 : /// Default constructor
14 1 : MqttNormalConnection();
15 :
16 : /// Initializes a new instance of the MqttConnection class.
17 0 : MqttNormalConnection.fromConnect(String server, int port) {
18 0 : connect(server, port);
19 : }
20 :
21 : /// Connect - overridden
22 : Future connect(String server, int port) {
23 1 : final Completer completer = new Completer();
24 : try {
25 : // Connect and save the socket.
26 2 : Socket.connect(server, port).then((socket) {
27 1 : client = socket;
28 2 : readWrapper = new ReadWrapper();
29 1 : _startListening();
30 1 : return completer.complete();
31 2 : }).catchError((e) => _onError(e));
32 : } catch (SocketException) {
33 : final String message =
34 0 : "MqttNormalConnection::The connection to the message broker {$server}:{$port} could not be made.";
35 0 : throw new NoConnectionException(message);
36 : }
37 1 : return completer.future;
38 : }
39 : }
|