IDisposable ListenFirstPacket()
        {
            var packetDueTime = TimeSpan.FromSeconds(configuration.WaitTimeoutSecs);

            return(channel
                   .ReceiverStream
                   .FirstOrDefaultAsync()
                   .Timeout(packetDueTime)
                   .Subscribe(async packet => {
                if (packet == default(IPacket))
                {
                    return;
                }

                var connect = packet as Connect;

                if (connect == null)
                {
                    await NotifyErrorAsync(ServerProperties.Resources.ServerPacketListener_FirstPacketMustBeConnect)
                    .ConfigureAwait(continueOnCapturedContext: false);

                    return;
                }

                clientId = connect.ClientId;
                keepAlive = connect.KeepAlive;
                connectionProvider.AddConnection(clientId, channel);

                tracer.Info(ServerProperties.Resources.ServerPacketListener_ConnectPacketReceived, clientId);

                await DispatchPacketAsync(connect)
                .ConfigureAwait(continueOnCapturedContext: false);
            }, async ex => {
                await HandleConnectionExceptionAsync(ex)
                .ConfigureAwait(continueOnCapturedContext: false);
            }));
        }
Example #2
0
        IDisposable ListenFirstPacket()
        {
            TimeSpan packetDueTime = TimeSpan.FromSeconds(_configuration.WaitTimeoutSecs);

            return(_channel
                   .ReceiverStream
                   .FirstOrDefaultAsync()
                   .Timeout(packetDueTime)
                   .Subscribe(async packet =>
            {
                if (packet == default(IPacket))
                {
                    return;
                }

                Connect connect = packet as Connect;

                if (connect == null)
                {
                    await NotifyErrorAsync(ServerProperties.ServerPacketListener_FirstPacketMustBeConnect);

                    return;
                }

                _clientId = connect.ClientId;
                _keepAlive = connect.KeepAlive;
                _connectionProvider.AddConnection(_clientId, _channel);

                _tracer.Info(ServerProperties.ServerPacketListener_ConnectPacketReceived(_clientId));

                await DispatchPacketAsync(connect);
            }, async ex =>
            {
                await HandleConnectionExceptionAsync(ex);
            }));
        }
 public void AddConnection(string clientId, IMqttChannel <IPacket> connection)
 {
     _connections.AddConnection(clientId, connection);
     _server.RaiseClientConnected(clientId);
 }