aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc/README.md')
-rw-r--r--jsonrpc/README.md18
1 files changed, 10 insertions, 8 deletions
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();