Пример #1
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 !!");
        }
Пример #2
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 !!");
        }