[SetNet & Console Application] First steps. SetNet.Server. Part 1

What is SetNet ? SetNet ( SetNet Server, sns ) - This is a network solution written in C # . With this solution, you can easily create applications that support network or network games.

Introduction


In this tutorial, we will learn how to connect the SetNet library to a console project. In the introduction, we will talk about what we need to connect and how the lessons themselves will be compiled.
What do we need:
Visual Studio 2007-2013
SetNet library
Hands from the shoulders

How will the lessons be compiled:


The first step in the lessons will be to understand all the base classes that are part of SetNet . In the first lesson, we will understand how to connect SetNet to the project and the first class that we need, SetNet.Server . Let's get started.
First Steps or Connecting a Library
So, it is time to connect the library to the project. To do this, you need the SetNet.dll file , which you can download (link above) and create a Console Application project. After the file is downloaded and the project is created, you need to connect the library.



RMB (Right mouse button) on "References" - "Add reference". After that, the “Reference Manager” window opens where we will add the library. Go to the “Browse” tab and click on the “Browse ...” button.



Select the library SetNet.dll . This completes the connection of the library.

We are writing a server


Now we need to write the basis of the server. After completing this lesson, the server can already be started. In this lesson we will look at the main server class through which the server automatically starts and accepts new clients.
First of all, create a new class using the key combination “ Ctrl + Shift + A ” or right click on the project - Add - Class and call it “ ServerClass ”. After these manipulations, we will have a class with the following content:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Server
{
    public class GameServer    
    {
    }
}


After that, we need to declare the SetNet namespace . To do this, write " using SetNet; "And will inherit the GameServer from SetNet.Server . After that, the class will look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SetNet;
namespace Server
{
    public class GameServer : Server    
    {
    }
}


Now all that remains for us is to implement an abstract class. To do this, RMB to the class from which we will inherit and select " Implement abstract class " and several override methods will appear :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SetNet;
namespace Server
{
    public class GameServer : Server    
    {
        public override void NewClient(ClientInfo info)
        {
        }
    }
}


It remains only to make the class constructor:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SetNet;
namespace Server
{
    public class GameServer : Server    
    {
 public GameServer()
            : base()
        {
        }
        public override void NewClient(ClientInfo info)
        {
        }
    }
}


Now let's analyze the class itself.


1.
using SetNet;
- Namespace.
2.
public override void NewClient(ClientInfo info)
- The method that is called when a new client connects.

This completes the first introductory lesson. If you still have questions, you can always contact me via e-mail rebegin@list.ru or skype haker954. Thanks.

Also popular now: