Expand description
§KCP Rust — High-Performance Async KCP
A modern, async-first implementation of the KCP (Fast and Reliable ARQ Protocol) built on top of Tokio.
§Architecture
┌───────────────────────────────────────┐
│ kcp-tokio (this crate) │
│ │
│ KcpStream / KcpListener ← user API │
│ actor ← scheduler │
│ transport ← UDP I/O │
├───────────────────────────────────────┤
│ kcp-core (dependency) │
│ │
│ KcpEngine ← pure sync state machine│
│ protocol ← wire types & constants │
└───────────────────────────────────────┘§Quick Start
use kcp_tokio::{KcpConfig, KcpStream};
use std::net::SocketAddr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr: SocketAddr = "127.0.0.1:8080".parse()?;
let config = KcpConfig::new().fast_mode();
let mut stream = KcpStream::connect(addr, config).await?;
use tokio::io::AsyncWriteExt;
stream.write_all(b"Hello, KCP!").await?;
use tokio::io::AsyncReadExt;
let mut buffer = [0u8; 1024];
let n = stream.read(&mut buffer).await?;
println!("Received: {:?}", &buffer[..n]);
Ok(())
}Re-exports§
pub use transport::Addr;pub use transport::Transport;pub use transport::UdpTransport;pub use config::KcpConfig;pub use error::KcpError;pub use error::Result;pub use stream::KcpStream;pub use listener::KcpListener;pub use kcp_core;
Modules§
- config
- Configuration types for KCP.
- engine
- Re-export of KcpEngine from kcp-core
- error
- Error types for KCP.
- listener
- KCP listener for accepting incoming connections
- protocol
- Core protocol types, constants, and wire format. KCP protocol types, constants, and utilities
- stream
- High-level async KCP stream interface
- transport
- Abstract transport layer for KCP