- Home /
Details on working with a home-hosted master server ?
More precisely, I would like to know what must be modified in the ConnectGUIMasterServer.js script of Unity's networking example to have it work reliably with a home-hosted master server, whatever the players' locations (LAN or external).
Thanks in advance :-)
Answer by jashan · Dec 16, 2009 at 11:00 PM
A home hosted master server might be a little troublesome. One of the things the master-server helps you with is NAT punchthrough - which requires that the machine the master-server is running on has a direct connection to the Internet, which usually is not the case for "home-based server".
So, unless you've got an Internet provider that gives you a public IP for your specific server and unless you have that server directly connected (without any IP-forwarding or NAT), it'll be hard to get connections created through such a home-based master server to be reliable.
That said: You can use MasterServer.ipAddress and MasterServer.port to let Unity know the data of your local MasterServer. Just make sure this is done before you actually use the MasterServer (e.g. for connecting), so you'd probably put the relevant statements right in the beginning of ConnectGuiMasterServer.js; something like:
private var testMessage = "Undetermined NAT capabilities";
// Enable this if not running a client on the server machine //MasterServer.dedicatedServer = true;
// => this is added START
MasterServer.ipAddress = "127.0.0.1"; // your public IP-address MasterServer.port = 12345; // the port your master-server uses (or leave that out if you use the default port)
// END until here ;-)
function OnFailedToConnectToMasterServer(info: NetworkConnectionError) { Debug.Log(info); }
So clear, concise and helpful ! I had missed the point about the master server needing to have a direct connexion to the internet, and thought that having a permanent public IP was enough. Thank you very much, Jashan, this is exactly the answer I needed :-)
Cheers,
Yann
Answer by Dreamora · Dec 17, 2009 at 12:12 PM
If you want to make it accessable to the outer world and would like to use one of the free static domain redirectors for that (no-ip.org / dyndns), then you need to expand the code slightly, as the ipAdress property of the master server etc only accepts the regular tupples. Also, you can not only set the master server adress and port but also the one of the connection tester and facilitator, which you will have to host along with the master server, should you require these functionalities. The connection tester will obviously handle the connection test, while the facilitator is used for the NATPunchthrough. Here is an example
string masterServerUrl = "master.yourdomain.no-ip.org"; System.Net.IPHostEntry ip = System.Net.Dns.GetHostEntry (masterServerUrl); System.Net.IPAddress[] ipA = ip.AddressList; if (ipA.Length > 0) { MasterServer.ipAddress = ipA[0].ToString(); MasterServer.port = 12345; }
masterServerUrl = "contester.yourdomain.no-ip.org"; ip = System.Net.Dns.GetHostEntry (masterServerUrl); ipA = ip.AddressList; if (ipA.Length > 0) { Network.connectionTesterIP = ipA[0].ToString(); Network.connectionTesterPort = 10735; }
masterServerUrl = "facilitator.yourdomain.no-ip.org"; ip = System.Net.Dns.GetHostEntry (masterServerUrl); ipA = ip.AddressList; if (ipA.Length > 0) { Network.natFacilitatorIP = ipA[0].ToString(); Network.natFacilitatorPort = 50000; }
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
What's the correct way to handle networked level loads? 0 Answers
How to watch in client applications what it is happening in the server one? 0 Answers
Networking with cells 0 Answers
Low Level API Networking 0 Answers