umbral-socket

Crates.ioumbral-socket
lib.rsumbral-socket
version0.2.9
created_at2025-07-26 05:18:34.068566+00
updated_at2025-08-10 16:25:57.06597+00
descriptionBytes server and client over Unix sockets
homepage
repositoryhttps://github.com/alan-venv/umbral-socket
max_upload_size
id1768832
size36,041
Alan Silva (alan-venv)

documentation

README

Umbral Socket

Bytes server and client over Unix sockets.

Installation

cargo add umbral-socket

How to Use

Below are basic examples for the server and client.

Server

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"))
}

Client

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))
    }
}
Commit count: 0

cargo fmt