Crates.io | rpc-core-net |
lib.rs | rpc-core-net |
version | 0.2.2 |
source | src |
created_at | 2023-11-28 10:13:08.946516 |
updated_at | 2023-12-16 11:58:32.191137 |
description | a tiny rpc library for rust |
homepage | https://github.com/shuai132/rpc_core |
repository | https://github.com/shuai132/rpc_core |
max_upload_size | |
id | 1051834 |
size | 49,147 |
Run the following Cargo command in your project directory:
cargo add rpc-core-net
Or add the following line to your Cargo.toml:
[dependencies]
rpc-core-net = "0.2.2"
See examples
for details: examples
server
fn server() {
let rpc = Rpc::new(None);
rpc.subscribe("cmd", |msg: String| -> String {
assert_eq!(msg, "hello");
"world".to_string()
});
let server = rpc_server::RpcServer::new(6666, RpcConfigBuilder::new().rpc(Some(rpc.clone())).build());
server.start();
}
client
fn client() {
let rpc = Rpc::new(None);
let client = rpc_client::RpcClient::new(RpcConfigBuilder::new().rpc(Some(rpc.clone())).build());
client.set_reconnect(1000);
client.open("localhost", 6666);
let result = rpc_c.cmd("cmd").msg("hello").future::<String>().await;
assert_eq!(result.result.unwrap(), "world");
}
This project is licensed under the MIT license.