Program.cs
When the DemoServer starts, Program.cs executes the Main() routine.
MessageServer.cs
Two functions are the main entry points for the message server:
-
MessageServer.cs - ConnectionListener
This thread listens for new connections to the server. When a new connection comes in, first Authentication.CheckAuthentication passes in the optional username and password fields from the client. In Demo server, Authentication.CheckAuthentication is currently set to always return true.
After the client has been successfully authenticated, an asynchronous task is started (LoginPlayer) - to connect the client with the server. Messages are sent and received asynchronously so that the server can communicate with several clients at the same time.
-
MessageServer.cs - UpdateLoop
This thread is a starting point for your server code. Any necessary background processes for your server should be put into this thread. A video game server may want to respawn enemies on this thread, or any other time-sensitive operations that are not based on messages to and from the client.
Networking/NetMessage.cs
This serves as our contract between the client and server, defining the structure of messages. All messages are sent as UTF-8, and are pipe-delimited string arrays. The first string in the message is always the unique Message Type ID, telling the client or server how to parse the message it is currently processing.