Table of Contents

Class ClientAdapter

Namespace
BSGameLib.Networking
Assembly
BSGameLib.Networking.dll

The client side of the network. It connects to a server, sends packets to it and runs the handlers for the packets it receives.

public class ClientAdapter : IClientAdapter, INetworkAdapter
Inheritance
ClientAdapter
Implements
Inherited Members

Constructors

ClientAdapter(ILogger, IDataPacketManager, NetworkAdapterConfiguration)

Creates a client adapter that connects with the QUIC settings in config.

public ClientAdapter(ILogger logger, IDataPacketManager packetManager, NetworkAdapterConfiguration config)

Parameters

logger ILogger
packetManager IDataPacketManager
config NetworkAdapterConfiguration

Properties

HandlerRunner

What each received packet's handler is run through, or null to run it where it arrives.

public Action<Type, Action> HandlerRunner { get; set; }

Property Value

Action<Type, Action>

Remarks

Packets arrive on the transport's receive threads: reliable ones one at a time, in order, on one thread, and unreliable ones on another, beside whatever thread runs the game's own loop. A game that wants handlers on its loop's thread sets this to something that queues them there; one that wants them one at a time with its own work sets it to something that takes its lock, runs the handler and lets go. It is given the packet's type, or null for one this side does not know, so that it can say which packet it is running: for timing them, say.

IsConnected

Whether there is a connection to the server.

public bool IsConnected { get; }

Property Value

bool

PacketManager

The packet manager that serializes and handles this adapter's packets.

public IDataPacketManager PacketManager { get; }

Property Value

IDataPacketManager

Methods

Connect(string, int)

Connects to the server at ipAddress and port. It blocks until the connection is made or fails.

public void Connect(string ipAddress, int port)

Parameters

ipAddress string
port int

Disconnect(string)

Closes the connection to the server, if there is one, and stops the client's transport. The reason is passed on in DisconnectReason; the server is not told it.

public void Disconnect(string reason = "")

Parameters

reason string

GetStatistics()

Traffic since this client started, and the connection to the server with its round-trip time, while there is one.

public NetworkStatistics GetStatistics()

Returns

NetworkStatistics

SendReliable<T>(T)

Sends packet to the server reliably and in order. Throws InvalidOperationException when not connected.

public void SendReliable<T>(T packet) where T : IDataPacket

Parameters

packet T

Type Parameters

T

Remarks

The size is checked before the packet is queued, so a packet too large for a frame throws here.

SendUnreliableSequenced<T>(T)

Sends packet to the server without delivery guarantees. The server drops it if a newer sequenced packet has already arrived. Throws InvalidOperationException when not connected.

public void SendUnreliableSequenced<T>(T packet) where T : IDataPacket

Parameters

packet T

Type Parameters

T

SendUnreliable<T>(T)

Sends packet to the server without delivery or order guarantees. Throws InvalidOperationException when not connected.

public void SendUnreliable<T>(T packet) where T : IDataPacket

Parameters

packet T

Type Parameters

T

Events

Connected

Raised when the connection to the server is made.

public event EventHandler<ClientEventArgs> Connected

Event Type

EventHandler<ClientEventArgs>

Disconnected

Raised when the connection to the server closes. DisconnectReason says why, when it is known.

public event EventHandler<ClientEventArgs> Disconnected

Event Type

EventHandler<ClientEventArgs>