KcpServerWrapper
A class in Alta.NetworkTransport.Runtime, Alta.NetworkingTransport.Kcp.
Server side of the KCP transport: wraps a kcp2k KcpServer as an ITransportServer and keeps one KcpServerConnection per connected player.
- Listed in Other Alta assemblies
- Inherits or implements
ITransportServer,ITransportSocket
Constructors
| Member | What it is |
|---|---|
KcpServerWrapper(KcpTransport transport, KcpSettings settings) | Creates a KcpServerWrapper from transport and settings. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private readonly Dictionary<int, KcpServerConnection> connections | Current connections keyed by kcp2k connection id. |
private static readonly Logger Logger | NLog logger for this class. |
private IPacketProcessor processor | The packet processor passed to the last ProcessIncoming call. |
private List<byte[]> receiveBuffersCache | Declared but never used in this build. |
private readonly KcpServer server | The kcp2k server; a KcpServerNonAlloc when KcpSettings.NonAlloc is on. |
private readonly KcpSettings settings | Declared but never assigned; the constructor reads its settings argument directly. |
private readonly KcpTransport transport | The KcpTransport this server belongs to, passed to each new connection. |
Properties
Events
| Member | What it is |
|---|---|
event Action<ITransportConnection> ConnectionCreated | Raised with the new connection when a client connects. |
event Action<ITransportConnection> ConnectionDestroyed | Raised with the connection after a client disconnects and it is removed from the list. |
event Action<AltaNetworkError> OnError | Raised with the converted error whenever kcp2k reports one for any connection. |
Methods
| Member | What it is |
|---|---|
ArraySegment<byte> CopyDataForCache(ArraySegment<byte> input, int processedBytes = 0) | Copies the unprocessed part of a received segment into a pooled 64 KB buffer from MessageReceivePool, so it can be kept after the callback. |
INetworkTransportResult ProcessIncoming(IPacketProcessor processor) | Stores the processor for HandleData, then ticks kcp2k's incoming side. Always returns success. |
INetworkTransportResult ProcessOutgoing() | Ticks kcp2k's outgoing side, flushing queued sends. Always returns success. |
void Start(ushort port) | Starts the kcp2k server listening on the given port. |
INetworkTransportResult Terminate() | Stops the kcp2k server. Always returns success. |
4 private and internal methods
| Member | What it is |
|---|---|
private void HandleConnection(int connectionIdentifier) | kcp2k connect callback; creates a KcpServerConnection for the id, stores it and raises ConnectionCreated. |
private void HandleData(int connectionId, ArraySegment<byte> data, KcpChannel channel) | kcp2k data callback. Reads the first byte as the game's channel and passes the rest to the processor; logs details and rethrows if that fails. |
private void HandleDisconnection(int connectionIdentifier) | kcp2k disconnect callback; removes the connection, marks it disconnected and raises ConnectionDestroyed. |
private void HandleError(int connectionId, ErrorCode error, string message) | kcp2k error callback; converts the code to an AltaNetworkError, raises OnError and logs it with the connection id. |