Esempio n. 1
0
        public Task Connect(IPEndPoint endpoint)
        {
            _connAcked = false;
            _broker.Connect(endpoint);

            var connect = new ConnectSendFlow(_manager);

            return(connect.Start(new Connect(ClientId, 300),
                                 startCmd =>
            {
                ResetTimer();
                _connAcked = true;
            }));
        }
Esempio n. 2
0
        public Task Connect(IPEndPoint endpoint,
                            ushort keepAliveSeconds = DefaultKeepAliveSeconds,
                            bool cleanSession       = false,
                            string userName         = null,
                            string password         = null)
        {
            _reconnectEndpoint  = endpoint;
            _reconnectKeepAlive = keepAliveSeconds;

            _client.Connect(endpoint).Await();
            _client.Receive();
            KeepAliveSeconds = keepAliveSeconds;
            _clientState     = ClientState.Connecting;

            var connectFlow = new ConnectSendFlow(_manager);

            var connectCommand = new Connect(ClientId, keepAliveSeconds);

            connectCommand.Details.ConnectFlags.CleanSession = cleanSession;
            if (string.IsNullOrEmpty(userName) == false)
            {
                connectCommand.Details.ConnectFlags.UserName = true;
                connectCommand.UserName = userName;
            }
            if (string.IsNullOrEmpty(password) == false)
            {
                connectCommand.Details.ConnectFlags.Password = true;
                connectCommand.Password = password;
            }

            return(connectFlow.Start(connectCommand, startCmd =>
            {
                _clientState = ClientState.Connected;
                ResetTimer();
            }));
        }