Game Creation with XNA/Networking/Network Engines

Network Engines
Other useful looking Engines:
 * WCF - Windows Communication Foundation
 * XNA integrated
 * RakNet

Other interesting facts and examples can be found here: http://create.msdn.com/en-US/education/catalog/?devarea=19, especially the one called Network Prediction.

Lidgren Network Engine
The Lidgren network engine is a .NET-based library made by Michael Lidgren. It can basically be used with every kind of .NET-Application. For delivery it uses a single udp socket and comes with classes for peer-to-peer and server-client connections. The engine runs under the MIT License, which makes it free to use. The current Version “gen3” requires .NET 3.5 or higher. Lidgren comes with an additional library that contains extension methods for some classes for a better XNA-Support. However you cannot use Lidgren for Xbox games.

Important Classes
NetPeer

NetPeer represents the local connection point. It holds and creates connections to other peers. Important derived classes are NetServer and NetClient, which contain appropriate modifications for a server-client-system.

NetOutgoingMessage

An Object of this class is the carrier for your information. To create one, you have to use the CreateMessage-method of your NetPeer object. With Write you can put all your data into the message. Write accepts all primitive types and objects.

NetIncomingMessage

This is used to hold the information about a received message. Additional to the content it says something about the MessageType, which can be library-related or data you have sent. *List of MessageTypes*

NetConnection

Represents the connection to a remote host.

Implementation
How to get started
 * 1) Download the latest version from the project's website.
 * 2) Open the "Lidgren XNA Extensions/Lidgren XNA Extensions.sln"-file and compile the solution.
 * 3) Copy the created .dll-files in your project folder and reference to them within your project.
 * 4) Now you should be able to use the Lidgren.Network namespace.

How to create a Peer

How to send a message

The different NetDeliveryMethods are explained here

How to receive a message

A description for all MessageTypes can be found here

How to connect to a server

The first step is to enable three specific message types.

After initialising the client you can search for the server. Therefore, you can send a request to an ip address or search all systems in your local network.

The server has now received a DiscoveryRequest which has to be handled by the "receive message loop"

The Client has now received a DiscoveryRequest by the server. Assuming there is just one server in your local network you can simply connect to it.

The last step is to receive the ConnectionApproval message at the server and to approve the connection.

Raknet
RakNet is a library with several classes to perform networking solutions and developed by Jenkins Software LL. It is a cross-platform for C++ and C#. Therefore, it can be used on all major platforms, including Android and iOS. Main features are object replication, lobby system, secure connections, voice communication and an autopatcher.

Swig
Swig can be used to generate wrapper code for a native DLL allowing to use RakNet in C#. Swing generates CXX and .h files that represent the interfaces as well as inclusions for the C# project to connect to the DLL. How to use Swig see the detailed description.

RakPeerInterface
Even though RakPeerInterface is not an actual class it is the main interface for the network communications and the responsible for the startup. An instance of a peer is return by calling the .GetInstance method.

SocketDescriptor
An instance describes the local socket which can be used for the startup. It is possible to define the port with parameters or use 0 to automatically pic a free port. In addition if desired an array of socket descriptors can be made.

Packet
It represents a message from another system/computer and contains information about the message, such as length, bit size or id of sender.

Connection as Server
Starting a server is very similar to the instructions above.

Reading of Packets
Remarks, Ii a packet is 0 nothing is to read.

Sending of Packets
Remarks, it is used BitStreams to create the "packets".

Links

 * Introduction to RakNet 4.0
 * Doxygen for Raknet
 * Support

Windows Communication Foundation
The Windows Communication Foundation (WCF) from Microsoft is a platform or application programming interface that bundles several technologies for building connected services or programs. Microsoft defines its features: orientation, interoperability, multiple message patters, service metadata, security and AJAZ and REST support. It supports SOAP over HTTP, TCP, Message Queues, etc. WCF requires Windows XP SP2 or higher.

Authors
mglaeser and juliusse