| Crates.io | umbral-socket |
| lib.rs | umbral-socket |
| version | 0.2.9 |
| created_at | 2025-07-26 05:18:34.068566+00 |
| updated_at | 2025-08-10 16:25:57.06597+00 |
| description | Bytes server and client over Unix sockets |
| homepage | |
| repository | https://github.com/alan-venv/umbral-socket |
| max_upload_size | |
| id | 1768832 |
| size | 36,041 |
Bytes server and client over Unix sockets.
cargo add umbral-socket
Below are basic examples for the server and client.
Example of how to start a server that receives data, prints it to the console, and pushes it in a Vec.
use std::{io::Result, sync::Arc};
use bytes::Bytes;
use tokio::sync::Mutex;
use umbral_socket::stream::UmbralServer;
#[derive(Clone, Default)]
struct State {
contents: Arc<Mutex<Vec<Bytes>>>,
}
#[tokio::main]
async fn main() -> Result<()> {
let state = State::default();
let socket = "/tmp/umbral.sock";
UmbralServer::new(state)
.route("POST", handler)
.run(socket)
.await
}
async fn handler(state: Arc<State>, content: Bytes) -> Result<Bytes> {
println!("CLIENT REQUEST: {}", String::from_utf8_lossy(&content));
state.contents.lock().await.push(content);
Ok(Bytes::from("OK"))
}
Example of how a client can send data to the server.
use bytes::Bytes;
use umbral_socket::stream::UmbralClient;
#[tokio::main]
async fn main() {
let socket = "/tmp/umbral.sock";
let pool_size = 1;
let client = UmbralClient::new(socket, pool_size);
let content = Bytes::from("{\"user\":\"alan\"}");
if let Ok(response) = client.send("POST", content).await {
println!("SERVER RESPONSE: {}", String::from_utf8_lossy(&response))
}
}