pub struct KcpConfig {
pub nodelay: bool,
pub interval: u32,
pub resend: i32,
pub nc: bool,
pub mtu: u32,
pub snd_wnd: u32,
pub rcv_wnd: u32,
pub stream_mode: bool,
}Expand description
KCP protocol configuration parameters.
Controls the behavior of the underlying KCP engine. Use the provided presets
(default(), fast(),
normal()) or customize individual fields.
§Example
use kcp_io::core::KcpConfig;
// Use a preset
let config = KcpConfig::fast();
// Customize from a preset
let config = KcpConfig {
mtu: 1200,
snd_wnd: 256,
rcv_wnd: 256,
..KcpConfig::fast()
};Fields§
§nodelay: boolEnable nodelay mode. When true, KCP disables the wait-to-send delay
and sends packets as soon as possible, reducing latency.
interval: u32Internal update interval in milliseconds. Lower values reduce latency but increase CPU usage. Typical range: 10–100 ms.
resend: i32Fast retransmit trigger count. When an out-of-order ACK is received this many times, KCP immediately retransmits the packet without waiting for a timeout. Set to 0 to disable fast retransmit.
nc: boolDisable congestion control. When true, KCP ignores the congestion
window and sends at full speed (uses nocwnd mode). Useful for
low-latency scenarios where bandwidth is not a concern.
mtu: u32Maximum Transmission Unit in bytes. This is the maximum size of a single KCP output packet (including the 24-byte KCP header). Must account for UDP header overhead (28 bytes for IPv4). Default: 1400.
snd_wnd: u32Send window size (number of packets). Larger values allow higher throughput but consume more memory. Default: 32.
rcv_wnd: u32Receive window size (number of packets). Should generally be >= snd_wnd.
Larger values allow higher throughput. Default: 128.
stream_mode: boolEnable stream mode. When true, KCP operates like a byte stream (similar
to TCP), merging small packets and splitting large ones. When false
(default), KCP preserves message boundaries.
Implementations§
Source§impl KcpConfig
impl KcpConfig
Sourcepub fn fast() -> Self
pub fn fast() -> Self
Returns a low-latency (fast) configuration preset.
Optimized for minimal latency at the cost of higher bandwidth usage.
- nodelay:
true - interval:
10ms - resend:
2(fast retransmit after 2 out-of-order ACKs) - nc:
true(congestion control disabled) - mtu:
1400 - snd_wnd:
128, rcv_wnd:128 - stream_mode:
false