Supported data types

Supported are all primative data types, which includes String Int16 Int32 Int64 Boolean Byte Char Decimal Double Single UInt16 UInt32 UInt64 Enums will be automatically mapped to an UInt32. In advance you can ship those types as Standalone As an array As a list public int Standalone { get; set; } public int[] Array { …

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; …

Library Setup

The easiest way to access the library is via NuGet. If Visual Studio doesn’t contain a NuGet Extension, download and install it manually. Instead of NuGet you can simply download the binaries. Setup with NuGet Expand the project, right click “References” and select “Manage NuGet Packages…” Search for “Network” or “Thomas Christof”, select the “Network by Thomas …