Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            LoggerConfig.SetSerilog();

            var server = TestRpcServer();
            var client = TestRpcClient();

            Task.WaitAll(server, client);


            var config = new MqttConfiguration("Mqtt");

            config.ClientId = "Test JsonRpcMqtt" + Guid.NewGuid();
            config.Username = "******";
            config.Password = "******";

            var mqtt    = new MqttClientHelper(config);
            var taskRun = mqtt.RunAsync();

            TestMqtt(mqtt);

            taskRun.Wait();
            mqtt.Disconnect();
        }
Exemplo n.º 2
0
        static Task TestRpcServer()
        {
            var config = new MqttConfiguration("Mqtt");

            config.ClientId = "Test JsonRpcMqtt" + Guid.NewGuid();
            config.Username = "******";
            config.Password = "******";

            var mqtt = new MqttClientHelper(config);


            var rpc = new Rpc(new JsonRpcMqttConnection(mqtt.Client, "test/", clientId: "TestRpcServer"));

            var functions = new ExampleService(rpc);

            rpc.Dispatcher.RegisterService(functions);

            mqtt.OnConnectionChange += (s, connected) => { if (connected)
                                                           {
                                                               rpc.UpdateRegisteredMethods();
                                                           }
            };

            return(mqtt.RunAsync());
        }
Exemplo n.º 3
0
 public Task RunAsync(CancellationToken?cancellationToken = null)
 {
     return(client.RunAsync(cancellationToken));
 }