nervo

Crates.ionervo
lib.rsnervo
version0.3.3
created_at2025-08-26 17:03:07.094837+00
updated_at2025-08-29 20:08:12.273629+00
descriptioneasy to use TCP library
homepage
repositoryhttps://github.com/VojtaKing/nervo
max_upload_size
id1811523
size4,961
VojtaKing (VojtaKing)

documentation

README

Nervo TCP Library

A simple Rust library for sending and receiving TCP messages in a separate thread.

Usage Sending messages

use nervo::send;

fn main() -> std::io::Result<()> {
    send("Hello", "127.0.0.1:8080")?;
    Ok(())
}

The send function connects to the specified TCP address and sends a single message. Each message should end with a newline (\n) for proper reception.

Receiving messages use nervo::rec;

fn main() {
    // Start TCP server and get a receiver for incoming messages
    let rx = rec(":8080");

    // Receive messages in real-time without blocking the main thread
    loop {
        if let Ok(msg) = rx.try_recv() {
            println!("Received: {}", msg);
        }

        // Other logic (game loop, GUI updates, etc.) can run here
    }
}

Pass the port as ":PORT" (e.g., ":8080").

The rec function runs the server in a separate thread and sends incoming messages via an mpsc channel.

For realtime applications, use try_recv() to avoid blocking your main thread.

Notes

Each TCP connection spawns a new thread, so multiple clients can connect simultaneously.

Make sure messages are newline-delimited (\n) for correct reception.

Suitable for realtime games, GUI apps, or simple TCP messaging systems.

Commit count: 15

cargo fmt