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(); }
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()); }
public Task RunAsync(CancellationToken?cancellationToken = null) { return(client.RunAsync(cancellationToken)); }