AstralKcp is a modified data transmission library based on KCP2k, specifically adapted for turn-based anime games.
AstralKcp provides a reliable communication protocol over UDP, optimized for gaming scenarios that require stable connections with low latency. The library delivers:
- Reliable data transmission similar to TCP but with reduced latency
- Network congestion control algorithms tailored for gaming scenarios
- Efficient bandwidth usage
- Optimizations for turn-based games where data integrity is more important than speed
- Low Latency: Specially optimized for gaming applications
- Congestion Control: Adaptive algorithms for various network conditions
- Reliability: Guaranteed packet delivery and ordering without the overhead of TCP
- Efficiency: Minimal resource usage while maintaining high performance
- Token Verification: Additional layer of security with token verification for segments
- Object Pooling: Efficient memory management to reduce garbage collection pressure
// Creating a KcpConversation instance
uint conversationId = 1; // Unique identifier for this conversation
uint token = 123456; // Security token
// Create the KCP instance with an output function to send data
var conversation = new KcpConversation(
conv: conversationId,
token: token,
output: (data, size) => SendUdpPacket(data, size)
);
// Configure the KCP instance
conversation.SetNoDelay(1, 10, 2, true); // Turbo mode for low latency
conversation.SetWindowSize(128, 128); // Set window sizes
conversation.SetMtu(1200); // Set MTU size
// Send data
byte[] data = PrepareGameData();
conversation.Send(data, 0, data.Length);
// Process incoming packets
// When you receive UDP packet:
conversation.Input(receivedData, 0, receivedData.Length);
// Receive data
byte[] buffer = new byte[4096];
int size = conversation.Receive(buffer, buffer.Length);
if (size > 0)
{
// Process received data
ProcessGameData(buffer, size);
}
// Update KCP regularly (e.g., in a game loop)
void Update(uint currentTimeMs)
{
conversation.Update(currentTimeMs);
}
// Dispose when done
conversation.Dispose();- .NET 9.0
- UDP socket support
MIT
This library is a modification of KCP2k, which is based on KCP.