Example #1
0
        //synchronized
        //[MethodImpl(MethodImplOptions.Synchronized)]
        public void connectToBroker()
        {
            if (isConnected() || isConnecting())
            {
                return;
            }

            if (mqttConnection == null)
            {
                if (!init())
                {
                    return;
                }
                mqttConnection = new MqttConnection(clientId, brokerHostName, brokerPortNumber, uid, password, new ConnectCB(this));
                mqttConnection.MqttListener = this;
            }

            try
            {
                // try to connect
                setConnectionStatus(MQTTConnectionStatus.CONNECTING);
                mqttConnection.connect();
            }
            catch (Exception e)
            {
                /* couldn't connect, schedule a ping even earlier? */
            }
        }