Skip to main content

KcpClientWrapper

A class in Alta.NetworkTransport.Runtime, Alta.NetworkingTransport.Kcp.

Client side of the KCP transport: wraps a kcp2k KcpClient as an ITransportClient, so the game's networking can connect, tick and receive through it.

Constructors​

MemberWhat it is
KcpClientWrapper(KcpTransport transport, KcpSettings settings)Creates a KcpClientWrapper from transport and settings.

Fields​

5 private and internal fields
MemberWhat it is
private readonly KcpClient clientThe kcp2k client; a KcpClientNonAlloc when KcpSettings.NonAlloc is on.
private readonly KcpClientConnection clientConnectionBacking field for Connection.
private static readonly Logger LoggerNLog logger for this class.
private IPacketProcessor processorThe packet processor passed to the last ProcessIncoming call.
private readonly KcpSettings settingsThe KCP tuning settings this client was made with.

Properties​

MemberWhat it is
ITransportConnection Connection { get; }The single KcpClientConnection to the server, used to send data.
int IncomingPacketsTotal { get; private set; }Count of data packets received and handed to the processor since this wrapper was made.
int OutgoingBytesTotal { get; }Total bytes sent, taken from the connection.
int OutgoingPacketsTotal { get; }Total packets sent, taken from the connection.
int OutgoingQueueSize { get; }Number of messages waiting in kcp2k's send queue.

Events​

MemberWhat it is
event Action<ITransportClient> ApprovedRaised when kcp2k reports the connection to the server is up.
event Action<ITransportClient> DisconnectedRaised after kcp2k reports the connection closed, once the connection object has been told.
event Action<AltaNetworkError> OnErrorRaised with the converted error whenever kcp2k reports one.

Methods​

MemberWhat it is
void Connect(string ipAddress, ushort port)Starts connecting to the given IP and port, passing every tuning value from the KcpSettings to kcp2k.
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 to use, then ticks kcp2k's incoming side. Always returns success.
INetworkTransportResult ProcessOutgoing()Ticks kcp2k's outgoing side, flushing queued sends. Always returns success.
INetworkTransportResult Terminate()Disconnects the kcp2k client. Always returns success.
4 private and internal methods
MemberWhat it is
private void HandleApproved()kcp2k connected callback; raises Approved.
private void HandleData(ArraySegment<byte> data, KcpChannel channel)kcp2k data callback. Reads the first byte as the game's channel, strips it and hands the rest to the current packet processor.
private void HandleDisconnected()kcp2k disconnected callback; marks the connection disconnected and raises Disconnected.
private void HandleError(ErrorCode error, string message)kcp2k error callback; converts the code to an AltaNetworkError, raises OnError and logs it.