From 4d51e3211740764764a6423f8ead4944e1790341 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sun, 19 Nov 2023 22:19:06 +0300 Subject: karyons jsonrpc implementation --- jsonrpc/examples/client.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 jsonrpc/examples/client.rs (limited to 'jsonrpc/examples/client.rs') diff --git a/jsonrpc/examples/client.rs b/jsonrpc/examples/client.rs new file mode 100644 index 0000000..0063098 --- /dev/null +++ b/jsonrpc/examples/client.rs @@ -0,0 +1,34 @@ +use serde::{Deserialize, Serialize}; + +use karyons_jsonrpc::Client; + +#[derive(Deserialize, Serialize)] +struct Req { + x: u32, + y: u32, +} + +#[derive(Deserialize, Serialize, Debug)] +struct Pong {} + +fn main() { + env_logger::init(); + smol::future::block_on(async { + let endpoint = "tcp://127.0.0.1:60000".parse().unwrap(); + let client = Client::new_with_endpoint(&endpoint, None).await.unwrap(); + + let params = Req { x: 10, y: 7 }; + let result: u32 = client.call("Calc.add", params).await.unwrap(); + println!("result {result}"); + + let params = Req { x: 10, y: 7 }; + let result: u32 = client.call("Calc.sub", params).await.unwrap(); + println!("result {result}"); + + let result: Pong = client.call("Calc.ping", ()).await.unwrap(); + println!("result {:?}", result); + + let result: String = client.call("Calc.version", ()).await.unwrap(); + println!("result {result}"); + }); +} -- cgit v1.2.3