コード例 #1
0
ファイル: InitializerSpec.cs プロジェクト: luyang14/mqtt-2
        public void when_initializing_server_then_succeeds()
        {
            var configuration = new MqttConfiguration {
                BufferSize = 131072,
                Port       = MqttProtocol.DefaultNonSecurePort
            };
            var binding     = new ServerTcpBinding();
            var initializer = new MqttServerFactory(binding);
            var server      = initializer.CreateServer(configuration);

            Assert.NotNull(server);

            server.Stop();
        }
コード例 #2
0
        protected async Task <IMqttServer> GetServerAsync(IMqttAuthenticationProvider authenticationProvider = null)
        {
            try {
                LoadConfiguration();

                var binding     = new ServerTcpBinding();
                var initializer = new MqttServerFactory(binding, authenticationProvider);
                var server      = initializer.CreateServer(Configuration);

                server.Start();

                return(server);
            } catch (MqttException protocolEx) {
                if (protocolEx.InnerException is SocketException)
                {
                    return(await GetServerAsync());
                }
                else
                {
                    throw;
                }
            }
        }