kcpserver

Crates.iokcpserver
lib.rskcpserver
version1.1.5
sourcesrc
created_at2020-09-11 04:19:58.993658
updated_at2024-07-01 03:39:08.061242
descriptionfast kcp server frame.
homepage
repositoryhttps://github.com/luyikk/kcp_server
max_upload_size
id287248
size107,050
(luyikk)

documentation

https://docs.rs/kcpserver

README

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

Commit count: 83

cargo fmt