MasterServer Is Public?

Hello Everyone

i’m little bit confused
about how to make Public Sever

At this moment i use :

Network.InitializeServer(numberOfPlayers, connectionPort, useNAT);

put there is 2 problem with that

1- its Private Server
2- I Cant Connect To This Unless If i know IP or Port, and using Hamachi or if its only for homenetwork


i read some about MasterServer
and i Coudnt Understand what is NAT

MasterServer.RegisterHost("MyUniqueGameType","JohnDoes game", "l33t game for all");

I Want To know If MasterServer is public?

for example i wanna Create Online Game
but i need it Dedicated server
So If I Used MasterServer Everything will be fine?

I Saw On Youtube How To Create My Own Master Server
Why i need to create My Own Server?
do i need it to make a Dedicated server?

Please if You Have Ideas / Info About Make Dedicated server
Help me out

and Sorry for my bad english

Well, where should i start. It seems you have problems to understand how “the Internet” works in general and what a server is. I try to explain it as short as i can :wink:

The Internet

The Internet is nothing but a network of many participants which are called peer. The general way simplified topology is like this:

[You] <--> [Your ISP] <--> [Internet Backbones] <--> [Another ISP] <--> [Somebody else]

ISP == Internet Service Provider

Every peer that wants to use the internet have to be connected somehow to the Internet. This is usually done by connecting to a local ISP (via DSL, telephone, glass fiber). Each peer that gets connected to the internet gets an IP-Address from the local ISP. This IP can be used by other peers to send you data. Exactly like a post address for mail. Every IP Address used on the Internet has to be unique since it tells all the routing hardware where a certain data packet has to go.

NAT Router (NPAT Router)

Nowadays it’s common practise to use a local router which connects your entire local area network to the Internet. But there’s a problem, each peer needs it’s own IP address or it can’t communicate with others in the net. The solution is Network (and Port) Address Translation. This technique actually misuse the port number inside the payload protocol(TCP or UDP) to map multiple users to the same IP address.
Here’s a picture how it basically works:

NAT router

That means from the Internet’s point of view there’s only one peer since the only one that’s connected to the internet is the router itself.

This technique works quite well for outgoing requests because the router can remember which of his local users has send an request into the internet. When the response arrives at the router, it can identify the actual target via the port number. However none of the users behind the router are actual internet peers, only the router is. That means none of the users can be reached from the internet.

Port forwarding

Most NAT router allows to specify so called port forwarding rules. That simply means that when the router receives a packet from the internet with a certain port number, it will simply forward the packet to the configured local user. The downside of this is a certain port can only be forwarded to one user.

This forwarding rule allows anyone on the internet to “directly connect” to a user behind the router.

What’s a server?

The term server is often confused because it can actually mean two different things:

  • A dedicated PC (hardware) which is optimised for a certain task
  • A software which handles connections from customers (clients) and provides a service to them (serves).

In most cases we actually talk about the second definition.

How does client-server-networking work

The player who runs the server actually runs the game. All other players have to connect to the server in order to take part of the game. If the player who runs the server is behind a NAT router, nobody outside of his local network can’t reach him (like explained above). So in order to connect the clients to the server it must be reachable from outside. When a NET router is used this can be achieved with port forwarding by adding an appropriate rule in the router settings. This is too complicated for most users, so we need another way.

The masterserver

A Unity masterserver is a special server which isn’t related to the actual game. It is just responsible to help peers to connect each other and to provide a list of available games.

This masterserver truly needs to be reachable from everyone. Each peer needs to know how they can connect to the master server. Big companies, like Unity Technologies, have bought fix IP addresses, so the address never changes. Unity runs such a master server for us, mainly for testing during development. This master server IP address is preconfigured in every Unity game. So if you don’t change the masterserver ip in your game you’re using UT’s test-masterserver.

If a player starts a game in “server mode” on his PC, the game would connect to the masterserver and register this game-server at the masterserver. This is done by using MasterServer.RegisterHost. You have to provide a “gameTypeName” and a “gameName”. the gameTypeName is actually the name of your game. This is used to actually find this game. The “gameName” could be anything, for example a user defined name like “Mike’s game”. This is just additional information.

Once the game is registrated, others can find it by requesting a host list from the server for a certain gameTypeName. So on the clients you have to call MasterServer.RequestHostList to ask the server if there are any servers registrated with the given gameTypeName.

The response might take a while until the whole list arrived. The client should call MasterServer.PollHostList to get a list of the available servers. One of the HostData elements in the returned array can be used to connect to this server. Simply pass the element to Network.Connect.

How does the masterserver make the clients connect directly?

The masterserver contains another server which is used for the connecting of a client to a game server. This part is called the facilitator. The facilitator just waits for players and tell them information about other players. As i mentioned above a NAT router will assign a certain port number to a local user when the user connects to an external server. This port number is usually used by the router to pass back the response to the correct local user. What the facilitator does is it just tells others which port the server player used to connect to the facilitator. Now other players can try to connect to the router of the game server owner by using the port number they got from the facilitator.

This technique is called NAT-Punch-Through. This is actually an abuse of a vulnerability in NAT routers. That’s why it doesn’t work with all routers.

To sum up

The Masterserver is just a special server which provides some kind of “lobby” functionality and help players which are located behind a NAT router to be able to run a local server.

The Masterserver isn’t involved in your actual game. It’s just used to connect the players with each other.

If you plan to have a lot players playing your game, you should consider to rent a server (now i mean the hardware) in a data center and host your own masterserver for your game. UT’s masterserver can be used, but it might be overloaded from time to time and is in general not that reliable. For small games with just a few players it’s ok to use the default masterserver.

So i failed miserably to keep this answer short :wink: Anyways i hope it helps a bit to understand for what purpose the Masterserver is used and what you have to do if you want to use it.