Table of Contents

Interface IServerAdapter

Namespace
BSGameLib.Networking
Assembly
BSGameLib.Networking.dll

The server side of the network. Clients connect, packets are sent to and from them, and the handlers for the packets they send are run.

public interface IServerAdapter : INetworkAdapter
Inherited Members

Properties

HandlerRunner

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

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

Property Value

Action<Type, Action>

Remarks

Packets arrive on the transport's threads, one handler per connection at once, beside whatever thread runs the game's own loop. A game whose world is to be touched by one thing at a time sets this to something that takes its lock, runs the handler and lets go; one that wants handlers on its loop's thread sets it to something that queues them. 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.

Methods

Disconnect(INetConnection, string)

Closes the connection to client. reason is sent to the client, which sees it as its disconnect reason.

void Disconnect(INetConnection client, string reason = "")

Parameters

client INetConnection
reason string

GetStatistics()

Traffic since the server started, and each connected client's, with its round-trip time.

NetworkStatistics GetStatistics()

Returns

NetworkStatistics

SendReliableThenDisconnect<T>(INetConnection, T, string)

Delivers one last packet and only then closes the connection -- a kick reason, a shutdown notice, anything the peer needs in order to explain itself to its user.

void SendReliableThenDisconnect<T>(INetConnection client, T packet, string reason = "") where T : IDataPacket

Parameters

client INetConnection
packet T
reason string

Type Parameters

T

Remarks

Needed because SendReliable<T>(INetConnection, T) is fire-and-forget: sending and then calling Disconnect(INetConnection, string) races, and the close normally wins, so the packet never reaches the wire. This waits for the write, with a timeout so an unresponsive peer cannot stall the disconnect.

SendReliable<T>(INetConnection, T)

Sends packet to client reliably and in order.

void SendReliable<T>(INetConnection client, T packet) where T : IDataPacket

Parameters

client INetConnection
packet T

Type Parameters

T

SendUnreliableSequenced<T>(INetConnection, T)

Sends packet to client without delivery guarantees. A packet that arrives after a newer one is dropped.

void SendUnreliableSequenced<T>(INetConnection client, T packet) where T : IDataPacket

Parameters

client INetConnection
packet T

Type Parameters

T

SendUnreliable<T>(INetConnection, T)

Sends packet to client without delivery or order guarantees.

void SendUnreliable<T>(INetConnection client, T packet) where T : IDataPacket

Parameters

client INetConnection
packet T

Type Parameters

T

Start()

Starts listening for clients on the port in the configuration.

void Start()

Stop()

Stops listening and closes every connection.

void Stop()

Events

Connected

Raised when a client connects.

event EventHandler<ClientEventArgs> Connected

Event Type

EventHandler<ClientEventArgs>

DataReceived

Raised for each frame received from any client, before its packet is handled.

event EventHandler<DataReceivedEventArgs> DataReceived

Event Type

EventHandler<DataReceivedEventArgs>

Disconnected

Raised when a client's connection closes.

event EventHandler<ClientEventArgs> Disconnected

Event Type

EventHandler<ClientEventArgs>

ForciblyDisconnected

Raised when the server closes a connection itself, through Disconnect(INetConnection, string) or SendReliableThenDisconnect<T>(INetConnection, T, string), just before it does.

event EventHandler<ClientEventArgs> ForciblyDisconnected

Event Type

EventHandler<ClientEventArgs>