Esempio n. 1
0
        public async Task <IMqttServer> StartServer(MqttServerOptionsBuilder options)
        {
            var server = CreateServer();

            options.WithDefaultEndpointPort(ServerPort);
            options.WithMaxPendingMessagesPerClient(int.MaxValue);

            await server.StartAsync(options.Build());

            return(server);
        }
Esempio n. 2
0
        public void changeServerConfig(ServerConfigData MQTTConfigData)
        {
            _theAuthenticator    = MQTTConfigData.Authenticator;
            _ServerConfiguration = new MqttServerOptionsBuilder();
            _ServerConfiguration.WithConnectionValidator(this);
            _ServerConfiguration.WithApplicationMessageInterceptor(this);
            _ServerConfiguration.WithSubscriptionInterceptor(this);
            _ServerConfiguration.WithClientId("Server");
            _ServerConfiguration.WithDefaultEndpointBoundIPAddress(MQTTConfigData.listenAdress);
            _ServerConfiguration.WithDefaultEndpointPort(MQTTConfigData.Port);
            _ServerConfiguration.WithMaxPendingMessagesPerClient(FedNetConstante.MAX_MESSAGE_PENDING);

            _logSystem.Info("reinitialisation finnised !!");
        }
Esempio n. 3
0
        public async Task <MqttServer> StartServer(MqttServerOptionsBuilder optionsBuilder)
        {
            optionsBuilder.WithDefaultEndpoint();
            optionsBuilder.WithDefaultEndpointPort(ServerPort);
            optionsBuilder.WithMaxPendingMessagesPerClient(int.MaxValue);

            var options = optionsBuilder.Build();
            var server  = CreateServer(options);
            await server.StartAsync();

            // The OS has chosen the port to we have to properly expose it to the tests.
            ServerPort = options.DefaultEndpointOptions.Port;
            return(server);
        }
Esempio n. 4
0
        public async Task <IMqttServer> StartServerAsync(MqttServerOptionsBuilder options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (Server != null)
            {
                throw new InvalidOperationException("Server already started.");
            }

            Server = new TestServerWrapper(_mqttFactory.CreateMqttServer(ServerLogger), TestContext, this);

            options.WithDefaultEndpointPort(ServerPort);
            options.WithMaxPendingMessagesPerClient(int.MaxValue);

            await Server.StartAsync(options.Build()).ConfigureAwait(false);

            return(Server);
        }
Esempio n. 5
0
        public FedNetServer(ServerConfigData MQTTConfigData, IFedNetLogger newlogSystem = null)
        {
            _logSystem = newlogSystem;
            if (_logSystem == null)
            {
                _logSystem = new DefaultLogger();
            }

            _theAuthenticator    = MQTTConfigData.Authenticator;
            _ServerConfiguration = new MqttServerOptionsBuilder();
            _ServerConfiguration.WithConnectionValidator(this);
            _ServerConfiguration.WithApplicationMessageInterceptor(this);
            _ServerConfiguration.WithSubscriptionInterceptor(this);
            _ServerConfiguration.WithClientId("Server");
            _ServerConfiguration.WithDefaultEndpointBoundIPAddress(MQTTConfigData.listenAdress);
            _ServerConfiguration.WithDefaultEndpointPort(MQTTConfigData.Port);
            _ServerConfiguration.WithMaxPendingMessagesPerClient(FedNetConstante.MAX_MESSAGE_PENDING);

            _theClientList = new List <ClientData>();
            _theGameServer = new MqttFactory().CreateMqttServer();
            _theGameServer.UseApplicationMessageReceivedHandler(e => {
                if (e.ClientId == "" || e.ClientId == " " || e.ClientId == null)
                {
                    return;
                }
                if (MessageReceived != null)
                {
                    MessageReceived.Invoke(this, Message.getMessage(e.ApplicationMessage));
                }
            });
            _theGameServer.UseClientConnectedHandler(e => {
                _logSystem.Info("new client connected : " + e.ClientId);
                //_theGameServer.SubscribeAsync("Server", FedNetConstante.CLIENT_TO_SERVER + FedNetConstante.DEFAULT_TOPIC_SEPARATOR + FedNetConstante.DEFAULT_TOPIC_JOKER, (MqttQualityOfServiceLevel)FedNetConstante.PRIORITY_SERVER_TO_CLIENT);
            });
            _theGameServer.StartedHandler            = this;
            _theGameServer.StoppedHandler            = this;
            _theGameServer.ClientDisconnectedHandler = this;

            _logSystem.Info("initialisation finished !!");
        }