From 7d6c0e68a19ad5e2e4e05cfc219d446be6ff2286 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Thu, 30 Nov 2023 22:52:53 +0300 Subject: jsonrpc: Enhance the API and add support for TCP, Unix, and TLS protocols. --- jsonrpc/README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'jsonrpc/README.md') diff --git a/jsonrpc/README.md b/jsonrpc/README.md index d937071..929d645 100644 --- a/jsonrpc/README.md +++ b/jsonrpc/README.md @@ -1,6 +1,7 @@ # karyons jsonrpc -A fast and lightweight async [JSON-RPC 2.0](https://www.jsonrpc.org/specification) implementation. +A fast and lightweight async implementation of [JSON-RPC +2.0](https://www.jsonrpc.org/specification), supporting the Tcp and Unix protocols. ## Example @@ -8,6 +9,7 @@ A fast and lightweight async [JSON-RPC 2.0](https://www.jsonrpc.org/specificatio use std::sync::Arc; use serde_json::Value; +use smol::net::{TcpStream, TcpListener}; use karyons_jsonrpc::{JsonRPCError, Server, Client, register_service, ServerConfig, ClientConfig}; @@ -20,15 +22,15 @@ impl HelloWorld { } } +let ex = Arc::new(smol::Executor::new()); + ////////////////// // Server ////////////////// -let ex = Arc::new(smol::Executor::new()); - // Creates a new server -let endpoint = "tcp://127.0.0.1:60000".parse().unwrap(); +let listener = TcpListener::bind("127.0.0.1:60000").await.unwrap(); let config = ServerConfig::default(); -let server = Server::new_with_endpoint(&endpoint, config, ex.clone()).await.unwrap(); +let server = Server::new(listener.into(), config, ex.clone()); // Register the HelloWorld service register_service!(HelloWorld, say_hello); @@ -38,12 +40,12 @@ server.attach_service(HelloWorld{}); ex.run(server.start()); ////////////////// -// Client +// Client ////////////////// // Creates a new client -let endpoint = "tcp://127.0.0.1:60000".parse().unwrap(); +let conn = TcpStream::connect("127.0.0.1:60000").await.unwrap(); let config = ClientConfig::default(); -let client = Client::new_with_endpoint(&endpoint, config).await.unwrap(); +let client = Client::new(conn.into(), config); let result: String = client.call("HelloWorld.say_hello", "world".to_string()).await.unwrap(); -- cgit v1.2.3