Packet structure

The most “complicated” thing with this library is clearly the packet structure. We have to keep some things in mind to guarantee a flawless serialization. We differ between two packet types. The Request and the response packet. Request Packet The request packet is used to “start” a conversation. We literally request something. public class CalculationRequest …

Send/Receive packets

The server can only register each packet type once. Therefore, on serverside we have to use the “RegisterStaticPacketHandler” method. That will map a packettype directly to the given delegate. In the following example we start to listen to a “CalculationRequest” after a connection has been established. public void Demo() { //1. Start listen on a …

Send and receive a packet async

//1. Establish a connection to the server. ClientConnectionContainer container = ConnectionFactory.CreateClientConnectionContainer(“127.0.0.1″, 1234); //2. Register what happens if we get a connection container.ConnectionEstablished += async (connection, type) => { Console.WriteLine($”{type.ToString()} Connection established”); //3. Send a request packet async and directly receive an answer. CalculationResponse response = await connection.SendAsync<CalculationResponse>(new CalculationRequest(10, 10)); Console.WriteLine($”Answer received {response.Result}”); };

Send and receive a packet with a delegate

public void Demo() { //1. Establish a connection to the server. container = ConnectionFactory.CreateClientConnectionContainer(“127.0.0.1″, 1234); //2. Register what happens if we get a connection container.ConnectionEstablished += connectionEstablished; } private void connectionEstablished(Connection connection, ConnectionType type) { Console.WriteLine($”{type.ToString()} Connection established”); //3. Register what happens if we receive a packet of type “CalculationResponse” container.RegisterPacketHandler<CalculationResponse>(calculationResponseReceived, this); //4. Send a …

Send and receive a packet in a lambda

//1. Establish a connection to the server. ClientConnectionContainer container = ConnectionFactory.CreateClientConnectionContainer(“127.0.0.1″, 1234); //2. Register what happens if we get a connection container.ConnectionEstablished += (connection, type) => { Console.WriteLine($”{type.ToString()} Connection established”); //3. Register what happens if we receive a packet of type “CalculationResponse” connection.RegisterPacketHandler<CalculationResponse>((response, con) => Console.WriteLine($”Answer received {response.Result}”), this); //4. Send a calculation request. connection.Send(new …

Client Setup

[TCP/UDP] ClientConnectionContainer The ClientConnectionContainer contains a TCP and a UDP connection by default. In addition the ClientConnectionContainer supports: Reconnecting if the TCP and/or the UDP connection has been lost Offering various methods to send data (async, fast, slow) Buffering packets if there is no available connection Remember your settings and packet-configurations after a reconnect public …

Server Setup

static void Main(string[] args) { //1. Create a new server container. ServerConnectionContainer serverConnectionContainer = ConnectionFactory.CreateServerConnectionContainer(1234, false); //2. Apply some settings serverConnectionContainer.AllowUDPConnections = true; //3. Set a delegate which will be called if we receive a connection serverConnectionContainer.ConnectionEstablished += ServerConnectionContainer_ConnectionEstablished; //4. Set a delegate which will be called if we lose a connection serverConnectionContainer.ConnectionLost += ServerConnectionContainer_ConnectionLost; …