Multiplayer with a single masterserver

Hey guys,
I want to make a Roleplay game (simple little reallife game) and need a multiplayer system.
I saw a lot of tutorials about this but these only were “player-hosted”.
Is there a example/tutorial how to make a masterserver?

Something like this:

e.G:
I open a console → Server startet on IP: xx.xx.xx.xx:xxxx → now my friends can connect to this server. (static IP defined in script).

Searched for tutorials but didn’t found one. I am kinda new in unity (experienced in C#).

Hope you can help me out!

Regards,
wuppi

So initially you’re talking about a “peer-to-peer” server architecture, where one of the peers (players) acts as both a client AND the server, and the other peers (players) act as clients only. What you are looking for is the “client-sever” architecture, where ALL peers (players) are clients, and they connect to a single dedicated server. There are clear differences between the two (mainly based on cost to maintain versus difficulty to implement), however I’ll let you work those out in your own time.

As for how to actually implement the client-server architecture, it’s very simple. First you will want to understand that your architecture (consisting of a client and a server) will consist of two seperate applications, both built in unity. One application will contain all of the client-related “stuff” (the client), while the other will contain all of the server-related “stuff” (the server).

Once you get your head around that, the next thing to understand is what a “client” and “server” is, in the client-server architecture. There is plenty of detailed information on this around the web so feel free to have a more in-depth look, but in short the client manages one single outgoing connection (to the server), while the server handles many incoming connections (from clients). Once you understand this, you pretty much understand the concept of client-server.

I’ll avoid posting code here, as I implore you to adventure into this yourself as there’s a lot of good stuff to learn here. However, to get you started, I suggest that you use the NetworkClient class (documented here: https://docs.unity3d.com/ScriptReference/Networking.NetworkClient.Connect.html) to handle your client side, and the NetworkServerSimple class (documented here: https://docs.unity3d.com/ScriptReference/Networking.NetworkServerSimple.html) to handle the server side. This should be enough to get you started.

Good luck!

1 Like