Overview of the C++ Implementation

Overview of the C++ Implementation

We have built a reference implementation of the protocol in C++ using the WinSock2 library. The code implements all the features of the specification described on the main page, as well as the following enhancements that are not part of the core specification itself:

Core Components

The structure of kNet is presented in the diagram below.

kNetStructure.png

The main interface to perform networking is the Network class. It allows the user to initiate new client connections or start up a server. The MessageConnection class represents an active connection, while the NetworkServer class provides all the necessary functionality for maintaining a listen server and multiple client connections.

To receive data from a connection, implement the IMessageHandler interface. To receive notifications about connection-related events on the server, implement the INetworkServerListener interface.

Reading and Writing Network Messages

The NetworkMessage class is used to build outbound messages. It has accessible member fields that correspond to the kNet Message Model specification. To serialize data, use the DataSerializer utility class and to parse received message streams, use the DataDeserializer class. Read the page Immediate Mode Data Serialization for an example on how to work with these classes.

Alternatively, avoid using immediate-mode serialization and manage the whole process automatically through serializable objects that are generated using the SerializationStructCompiler class. For more details on this, see Declarative Mode Data Serialization.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines