lynn_tcp

Crates.iolynn_tcp
lib.rslynn_tcp
version1.2.0-rc.1
created_at2025-01-25 02:17:32.07209+00
updated_at2025-08-26 20:14:01.027182+00
descriptionLightweight asynchronous TCP framework
homepage
repositoryhttps://github.com/cherish-ltt/lynn_tcp
max_upload_size
id1530180
size244,319
ysx (cherish-ltt)

documentation

README

Lynn_tcp

Crates.io MIT licensed doc Downloads

English|简体中文

Lynn_tcp is a lightweight TCP server framework


Keywords

  • Lightweight: concise code that is easier to learn and use

  • Concurrent and Performance: Based on Tokio's excellent asynchronous performance, it is easy to achieve concurrent processing capabilities for multi-user links

  • Lower latency: Design with read and write separation to achieve lower latency

  • Single Server: Focused on providing TCP service development for single server

  • Security: Code written with strong typing and memory safety in Rust

    tips: Lynn_tcp is mainly used for message forwarding and long link TCP game servers

    Quickly develop suitable business scenarios based on frameworks

    Different message parsing, communication data encryption, and other operations can be achieved through custom settings

Simple Use

Dependencies

Make sure you activated the features which you need of the lynn_tcp on Cargo.toml:

full features

Use cargo add lynn_tcp or:

[dependencies]
lynn_tcp = "1"

server feature

[dependencies]
lynn_tcp = { version = "1" , features = "server" }

client feature

[dependencies]
lynn_tcp = { version = "1" , features = "client" }

Server

use lynn_tcp::{lynn_server::*, lynn_tcp_dependents::*};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize tracing or use app.logserver()
    tracing_subscriber::fmt::init();
    let _ = LynnServer::new()
        .await
        .add_router(1, my_service)
        .add_router(2, my_service_with_buf)
        .add_router(3, my_service_with_clients)
        .start()
        .await;
    Ok(())
}

pub async fn my_service() -> HandlerResult {
    HandlerResult::new_without_send()
}
pub async fn my_service_with_buf(input_buf_vo: InputBufVO) -> HandlerResult {
    println!(
        "service read from :{}",
        input_buf_vo.get_input_addr().unwrap()
    );
    HandlerResult::new_without_send()
}
pub async fn my_service_with_clients(clients_context: ClientsContext) -> HandlerResult {
    HandlerResult::new_with_send(1, "hello lynn".into(), clients_context.get_all_clients_addrs().await)
}

Server with config

use lynn_tcp::{lynn_server::*, lynn_tcp_dependents::*};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize tracing or use app.logserver()
    tracing_subscriber::fmt::init();
    let _ = LynnServer::new_with_config(
        LynnServerConfigBuilder::new()
            .with_addr("0.0.0.0:9177")
            .with_server_max_connections(Some(&200))
            // Suggestion 256-512
            .with_server_max_taskpool_size(&512)
            // ...more
            .build(),
    )
    .await
    .add_router(1, my_service)
    .add_router(2, my_service_with_buf)
    .add_router(3, my_service_with_clients)
    .start()
    .await;
    Ok(())
}

pub async fn my_service() -> HandlerResult {
    HandlerResult::new_without_send()
}
pub async fn my_service_with_buf(input_buf_vo: InputBufVO) -> HandlerResult {
    println!(
        "service read from :{}",
        input_buf_vo.get_input_addr().unwrap()
    );
    HandlerResult::new_without_send()
}
pub async fn my_service_with_clients(clients_context: ClientsContext) -> HandlerResult {
    HandlerResult::new_with_send(
        1,
        "hello lynn".into(),
        clients_context.get_all_clients_addrs().await,
    )
}

Client

use lynn_tcp::{
    lynn_client::LynnClient,
    lynn_tcp_dependents::*,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize tracing or use app.logserver()
    tracing_subscriber::fmt::init();
    let client = LynnClient::new_with_addr("127.0.0.1:9177")
            .await
            .start()
            .await;
    let _ = client.send_data(HandlerResult::new_with_send_to_server(1, "hello".into())).await;
    let input_buf_vo = client.get_receive_data().await.unwrap();
    Ok(())
}

Features

  • server: Provide customizable TCP services that can easily achieve multi-user long connections and concurrent processing capabilities, with services for different routes
  • client: Provides a custom TCP client that sends and receives messages to and from a TCP server

Road maps

Basic functions

✅ Tcp server

✅ Tcp client

✅ Custom message parsing

✅ Automatically clean sockets

✅ Routing service for asynchronous tasks

Note:

All Basic functions support on v1.0.0 and above

Extended functions

✅ TLS1.3 (support on v1.2.0 and above)

Scheduled tasks

Middleware

Global database handle

Disconnecting reconnection mechanism

Note:

If you haven't seen clear instructions, it's currently unavailable and still under development

Flow chart

FlowChart.png

FlowChart

Release note

version.md

Test results

platform: Debian12.9 (4H4G)

model-1: one request by one response

model-2: concurrent send request and recv response

total-time: 20s

version: lynn_tcp-v1.1.x

client concurrency model-1(Responses/Seconds) model-2(Responses/Seconds)
256 182,879 80,499
512 249,135 61,370
1024 232,861 23,143
2048 185,735 16,468
4096 160,318 13,557

version: lynn_tcp-v1.2.x

client concurrency model-1(Responses/Seconds) model-2(Responses/Seconds)
256 45,816 437,347
512 182,296 259,459
1024 163,307 140,934
2048 131,346 59,427
4096 124,645 37,034

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Lynn_tcp by you, shall be licensed as MIT, without any additional terms or conditions.

Commit count: 165

cargo fmt