Usage
The basic usage for application to integrate with KCP:
-
Create a KCP object:
-
Setup the callback function:
-
Update the states of KCP:
-
Notify KCP when data received from peer:
-
Done:
User can now use ikcp_send to send packets to peer.
Peer can use ikcp_recv to receive packets from peer.
Config KCP
The default mode of KCP is a standard ARQ,
user can setup the bellow options for low latency:
-
Work mode
- nodelay: Whether enable
nodelay mode. 0: Off; 1: On.
- interval: The internal interval in milliseconds, such as 10ms or 30ms.
- resend: Whether enable fast retransmit mode. 0: Off; 2: Retransmit when missed in 2 ACK.
- nc: Whether disable the flow control. 0: Enable. 1: Disable.
- For normal mode, like TCP:
ikcp_nodelay(kcp, 0, 40, 0, 0);
- For high efficient transport:
ikcp_nodelay(kcp, 1, 10, 2, 1);
-
Window size
Setup the max send or receive window size in packets, default to 32 packets. Similar to TCP SO_SNDBUF and SO_RECVBUF, but they are in bytes, while ikcp_wndsize in packets.
-
MTU
The MTU(Maximum Transmission Unit) default to 1400 bytes, which can be set by ikcp_setmtu. Notice that KCP never probe the MTU, user must tell KCP the right MTU to use if need.
-
Minimum RTO
Both TCP and KCP use minimum RTO, for example, when calculated RTO is 40ms but default minimum RTO is 100ms, then KCP never detect the dropped packet util after 100ms. The default value of minimum RTO is 100ms for normal mode, while 30ms for high efficient transport.
User can setup minimum RTO by: