aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/examples
diff options
context:
space:
mode:
authorhozan23 <hozan23@proton.me>2023-11-30 22:52:53 +0300
committerhozan23 <hozan23@proton.me>2023-11-30 22:52:53 +0300
commit7d6c0e68a19ad5e2e4e05cfc219d446be6ff2286 (patch)
tree2f7bfc34ca033b059702fc26bc18170dc118c20e /jsonrpc/examples
parent8c70a0d379b21541b5b2d1d37ff7fc61ca311cd4 (diff)
jsonrpc: Enhance the API and add support for TCP, Unix, and TLS protocols.
Diffstat (limited to 'jsonrpc/examples')
-rw-r--r--jsonrpc/examples/client.rs5
-rw-r--r--jsonrpc/examples/server.rs7
2 files changed, 6 insertions, 6 deletions
diff --git a/jsonrpc/examples/client.rs b/jsonrpc/examples/client.rs
index 6b60233..8f46a8e 100644
--- a/jsonrpc/examples/client.rs
+++ b/jsonrpc/examples/client.rs
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
+use smol::net::TcpStream;
use karyons_jsonrpc::{Client, ClientConfig};
@@ -14,9 +15,9 @@ struct Pong {}
fn main() {
env_logger::init();
smol::future::block_on(async {
- 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 params = Req { x: 10, y: 7 };
let result: u32 = client.call("Calc.add", params).await.unwrap();
diff --git a/jsonrpc/examples/server.rs b/jsonrpc/examples/server.rs
index 512913a..4109e0d 100644
--- a/jsonrpc/examples/server.rs
+++ b/jsonrpc/examples/server.rs
@@ -2,6 +2,7 @@ use std::sync::Arc;
use serde::{Deserialize, Serialize};
use serde_json::Value;
+use smol::net::TcpListener;
use karyons_jsonrpc::{register_service, JsonRPCError, Server, ServerConfig};
@@ -43,11 +44,9 @@ fn main() {
let ex = Arc::new(smol::Executor::new());
smol::block_on(ex.clone().run(async {
// 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)
- .await
- .unwrap();
+ let server = Server::new(listener.into(), config, ex);
// Register the Calc service
register_service!(Calc, ping, add, sub, version);