#kcp

kcpserver

fast kcp server frame

26 releases (9 stable)

1.1.2 Mar 6, 2023
1.0.4 Feb 28, 2023
0.3.2 May 25, 2022
0.3.1 Feb 2, 2021
0.2.7 Oct 30, 2020
Download history 27/week @ 2023-05-30 1/week @ 2023-06-13 27/week @ 2023-06-20 51/week @ 2023-06-27 2/week @ 2023-07-04 1/week @ 2023-07-25 1/week @ 2023-08-01 16/week @ 2023-08-08 27/week @ 2023-08-15 461/week @ 2023-08-22 95/week @ 2023-08-29 56/week @ 2023-09-05 1/week @ 2023-09-12

613 downloads per month

MIT/Apache

74KB
1.5K SLoC

kcpserver

Latest Version Rust Documentation Rust Report Card Rust CI

最好用的RUST KCP 服务器框架 (The best rust kcp server framework)

Examples Echo

use kcpserver::prelude::{
    kcp_module::{KcpConfig, KcpNoDelayConfig},
    *,
};
use tokio::io::AsyncReadExt;
use log::LevelFilter;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    env_logger::Builder::new()
        .filter_level(LevelFilter::Debug)
        .init();

    let mut config = KcpConfig::default();
    config.nodelay = Some(KcpNoDelayConfig::fastest());
    let kcp_server = KcpListener::new("0.0.0.0:5555", config, 1, |peer| async move {
        log::debug!("create kcp peer:{}", peer);
        let mut buf = [0; 1024];
        let mut reader = peer.get_reader();
        let mut writer = peer.get_writer();
        while let Ok(size) = reader.read(&mut buf).await {
            log::debug!("read peer:{} buff:{}", peer, size);          
            writer.write_all(&buf[..size]).await?;
            writer.flush().await?;
        }
        writer.shutdown().await?;
        log::debug!("kcp peer:{} closed", peer.to_string());
        Ok(())
    })?;
    kcp_server.start().await?;
    Ok(())
}

Dependencies

~6–17MB
~193K SLoC