KKRainbow 268533568d
CI / Lint (push) Canceled after 0s
CI / Linux arm64 (debug) (push) Canceled after 0s
CI / Linux arm64 (release) (push) Canceled after 0s
CI / Linux x64 (debug) (push) Canceled after 0s
CI / Linux x64 (release) (push) Canceled after 0s
CI / Windows arm64 (debug) (push) Canceled after 0s
CI / Windows arm64 (release) (push) Canceled after 0s
CI / Windows x64 (debug) (push) Canceled after 0s
CI / Windows x64 (release) (push) Canceled after 0s
CI / macOS arm64 (debug) (push) Canceled after 0s
CI / macOS arm64 (release) (push) Canceled after 0s
CI / macOS x64 (debug) (push) Canceled after 0s
CI / macOS x64 (release) (push) Canceled after 0s
CI / Cross aarch64-unknown-linux-musl (debug) (push) Canceled after 0s
CI / Cross riscv64gc-unknown-linux-musl (debug) (push) Canceled after 0s
CI / Cross x86_64-unknown-linux-musl (debug) (push) Canceled after 0s
CI / Cross aarch64-unknown-linux-musl (release) (push) Canceled after 0s
CI / Cross riscv64gc-unknown-linux-musl (release) (push) Canceled after 0s
CI / Cross x86_64-unknown-linux-musl (release) (push) Canceled after 0s
test: keep one historical KCP compatibility baseline
Remove the intermediate b37ee660 dev-dependency and its duplicate
compatibility cases. Keep the pre-negotiation d7427c22 endpoint as
the maintained legacy baseline.

Flatten the single-use test macro into ordinary test functions and
retain negotiation, bidirectional data, half-close, and duplicate SYN
assertions. Protocol implementation files are unchanged.

Validation: all 31 tests and strict Clippy pass.
2026-09-14 22:04:54 +08:00
2025-01-27 23:04:55 +08:00
2026-05-15 13:04:37 +08:00
2025-01-27 23:05:35 +08:00
2025-01-10 23:03:37 +08:00
2025-01-10 23:03:37 +08:00
2025-01-27 23:04:55 +08:00

kcp-sys

Safe bindings to the kcp transport protocol library.

Also including a high level API for connection state management and data stream handling.

Usage

  1. Create the endpoint and run it.

    let mut endpoint = KcpEndpoint::new();
    endpoint.run().await;
    
  2. forward the input and output to your transport layer, udp for example.

    let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
    
    let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54320").await.unwrap());
    udp_socket.connect("127.0.0.1:54321").await.unwrap();
    
    let udp = udp_socket.clone();
    tokio::spawn(async move {
        while let Some(data) = output.recv().await {
            udp.send(&data.inner()).await.unwrap();
        }
    });
    
    let udp = udp_socket.clone();
    tokio::spawn(async move {
        loop {
            let mut buf = vec![0; 1024];
            let (size, _) = udp.recv_from(&mut buf).await.unwrap();
            input
                .send(BytesMut::from(&buf[..size]).into())
                .await
                .unwrap();
        }
    });
    
  3. Create a connection and send / recv data.

    let conn_id = endpoint
        .connect(Duration::from_secs(1), 0, 0, Bytes::new())
        .await
        .unwrap();
    
    let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
    kcp_stream.write_all(b"hello world").await.unwrap();
    
    let mut buf = vec![0; 64 * 1024];
    let size = kcp_stream.read(&mut buf).await.unwrap();
    
    println!("{}", String::from_utf8_lossy(&buf[..size]));
    

Tune the kcp parameters

You can tune the kcp parameters by set a config factory to the endpoint.

let mut endpoint = KcpEndpoint::new();
endpoint.set_kcp_config_factory(|conv| {
    KcpConfig::new_turbo(conv)
});
S
Description
Safe bindings for KCP transport protocol.
Readme MIT
219 KiB
Languages
Rust 100%