This is a “MasterServer” similar to the MasterServer that shipped with the old Raknet based networking system. The project is implemented using the HLAPI messaging system, not using [Command]s and [ClientRpc] calls, so it uses the MessageBase class to define messages which are registered with handler functions. The file Master.cs contains the network protocol built with these messages.
There are two components, a MasterServer and a MasterClient. The MasterClient has an API similar to the old network system. There is a simple UI for controlling each component.
The MasterServer uses the NetworkServer class and listens for connections from MasterClients - which use the NetworkClient class. It allows clients to register as hosts with a name and a gameType, and to request a list of hosts by gameType. The list of hosts that is returned includes IP address and port.
So this could be used for local matchmaking - not over the internet unless all the hosts have public IPs.
In all the documentation pages and in this example it uses the localhost as the IP (127.0.0.1). How do I actually find the IP of the server from the client perspective?
This is something that would need to be known in advance. Your client would ship knowing that address or of a way to find it from some external service you host.
I’m currently evaluating whether I want to create my own master server or utilize Unity’s multiplayer services, and I had a quick question about your example here.
You stated that this cannot be used over the internet, but it would still be possible to use the connection information on the master server to perform a primitive NAT punchthrough, correct? I recognize that this wouldn’t work on stricter NAT setups that require the packets to come from the IP it initially connected to.
For bonus points, I’ve actually got a few questions about the multiplayer services that I haven’t found any answers to:
Do you know when any pricing and restriction information will be announced? I’d like to have all of the facts before I commit to using the services as the underlying tech for my game. I read a thread that had limits based on messages and message size that placed limits at 30msg/s and 150 bytes per message. Is this incoming, outgoing, or both?
1a. In addition, the networking profiler doesn’t seem to give any information about message sizes?
1b. How good at buffering messages is the SyncVar system, and will the compression/buffering work to keep the message < 150 bytes?
1c. Is it possible to use the matchmaker without the relay server, and simply use NAT punchthrough in the method above?
Do you have any information about relay server geographical locations, and any sort of performance metrics for how having the relay server affects ping?
Yes, in a case of an online multiplayer game. But, if you are making a local multiplayer game over WiFi, there is no way to find out the IP using the HL API.
The only way you can do it is by using the Transport Layer with Broadcast functionality, which currently doesn’t work on mobile… (pc tests were successful).
So, is there something planned for HL API that mimics the Broadcasting functionality of LL API?
Quick question, does this sample or Init’ing a server in HLAPI open both UDP and TCP hosts to accommodate WebGL? I’ve only seen examples for WebGL hosts on LLAPI unless I missed a page somewhere.
Also, would I be able to design an Authoritative server (internet) without any usage of the Unity service (ie, no Unity-based limits)?
As a former network engineer, my advice is: when you ship a game, don’t ever hard code the IP. use a name like mygame.domain.com. This way if your IP change it won’t kill your game. Use one of the free DNS service on the Internet to setup a name that points to your IP. For testing locally on your machine, you can put the name in your HOST file, and have it point to your loopback (127.0.0.1)… Example, while working on your game you can edit your “hosts” file in your “windows\system32\drivers\etc” to add the following
So when the uNet phase 2 will start, so we will be able to use it outside Unity3D engine ?
I like Unity3D for physics, navigation and stuff. Unity engine instance is perfect for hosting a game server, but for things like master server it’s different.
Old mono version doesn’t allow us to use the new async programming introduced in C# 4.
Right now I can’t find any way to keep MSSQL server calls away from blocking threads on unity’s mono, and the overhead of Unity engine for simple things like this is gigantic.
UPD: Nevermind, found the answer myself in here Platform roadmaps | Unity
Standalone simulation server should be available in 16 mar of 2016
Can this master server be used to register both clients (players) and servers? And can players still be connected to the master server while connected to a game server?
I am using this as template and works pefect for PC builds, but on Android WiFi I get random disconnects every few seconds. Increasing timeout or spamming packets to keep connection alive did not help. It happens if I sent data or do nothing - client simply disconnects. Any idea what I am missing here? I am on the Unity 5.3.?p5
I used your MasterServer code above, and did CLIENT ONLY build for WebGL. Basically i disabled the server gameobject and left the client only enabled.
The server was running in the Unity editor.
When i run the WebGL client code in FireFox browser and try to connect to the server running in the unity editor, i get this message:
Firefox can’t establish a connection to the server at ws://127.0.0.1:45555/.
Error: undefined socket will be closed
Client Disconnected from Master
OnFailedToConnectToMasterServer
Anybody knows how i can fix it? Im trying to make a server that can host multiple rooms to WebGL browser clients, but it dont work using your MasterServer code that i downloaded.
I got it to work, locally, and uploading to external server, could connect two players to it and it displayed their created game.
Do we have a Facilitator? Or connection tester update for Unity 5 unet?
I have all my own servers so theres no need for Unity to host them, however i do need the programmes XD
Thanks for the work so far @seanr
My previous multiplayer games were using the old legacy system, i have a few million downloads in total and the removal of legacy networking is starting to screw me over XD