Crates.io | kumoko |
lib.rs | kumoko |
version | 0.6.0 |
source | src |
created_at | 2022-07-24 18:24:18.009555 |
updated_at | 2023-06-28 14:43:20.010609 |
description | A simple asynchronous server/client crate built on tokio for easy two-way streaming. |
homepage | |
repository | https://github.com/BR03D/kumoko.git |
max_upload_size | |
id | 632130 |
size | 43,923 |
A simple asynchronous server/client crate built on tokio for easy two-way streaming.
Enable asynchronous full duplex streaming of semi-complex data-structures between a rust server and clients. gRPC implementations are suboptimal for this:
Message
can be transmitted:trait Message: Send + Encode + Decode + 'static
In your Cargo.toml:
[dependencies]
kumoko = "0.5"
tokio = { version = "1.20", features = ["macros", "rt-multi-thread"] }
Minimal Client:
use kumoko::client::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Client::connect("[::1]:50052").await?;
client.emit_request("Ferris".to_string()).await;
let msg: String = client.get_response().await.unwrap();
println!("{}", msg);
Ok(())
}
Minimal Server:
use kumoko::server::Server;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut server = Server::<String, String>::bind("[::1]:50052").await?;
loop{
let (req, origin) = server.get_request().await;
let msg = format!("Hello {}! Happy to see you here!", req);
server.emit_response(msg, origin.into()).await;
}
}