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.
- Listed in Other Alta assemblies
- Inherits or implements
ITransportClient,ITransportSocket
Constructors
| Member | What it is |
|---|---|
KcpClientWrapper(KcpTransport transport, KcpSettings settings) | Creates a KcpClientWrapper from transport and settings. |
Fields
5 private and internal fields
| Member | What it is |
|---|---|
private readonly KcpClient client | The kcp2k client; a KcpClientNonAlloc when KcpSettings.NonAlloc is on. |
private readonly KcpClientConnection clientConnection | Backing field for Connection. |
private static readonly Logger Logger | NLog logger for this class. |
private IPacketProcessor processor | The packet processor passed to the last ProcessIncoming call. |
private readonly KcpSettings settings | The KCP tuning settings this client was made with. |
Properties
| Member | What 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
| Member | What it is |
|---|---|
event Action<ITransportClient> Approved | Raised when kcp2k reports the connection to the server is up. |
event Action<ITransportClient> Disconnected | Raised after kcp2k reports the connection closed, once the connection object has been told. |
event Action<AltaNetworkError> OnError | Raised with the converted error whenever kcp2k reports one. |
Methods
| Member | What 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
| Member | What 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. |