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); })); }