For those of you who need an alternative solution to the Unity Technologies hosted servers, dimeRocker is pleased to offer dR hosted servers: a Unity MasterServer, NAT Facilitator and Connection Tester conveniently located in North America.
While you’re at it, sign-up so we can keep you posted on all the social gaming APIs we are developing specifically for Unity that will allow devs like yourselves to deploy, enrich, recoup and manage your games across the web from one centralized source. Sign-up here: http://dimerocker.com/devsignup/
dR Server deets:
masterserver.dimerocker.com
port: 12345
connectiontester.dimerocker.com
port: 10735
facilitator.dimerocker.com
port: 50000
The IPs for these servers may change, but the subdomains will always point where you need to go. You will need to resolve the URLs to IPs to connect from within your Unity game. Here’s snippets to do that.
Javascript:
var masterServerUrl = "masterserver.dimerocker.com";
var ip = System.Net.Dns.GetHostEntry (masterServerUrl);
var ipA = ip.AddressList;
if (ipA.Length > 0)
{
MasterServer.ipAddress = ipA[0].ToString();
MasterServer.port = 12345;
}
var connectionTesterUrl = "connectiontester.dimerocker.com";
ip = System.Net.Dns.GetHostEntry (connectionTesterUrl);
ipA = ip.AddressList;
if (ipA.Length > 0)
{
Network.connectionTesterIP = ipA[0].ToString();
Network.connectionTesterPort = 10735;
}
var natFacilitatorUrl = "facilitator.dimerocker.com";
ip = System.Net.Dns.GetHostEntry (natFacilitatorUrl);
ipA = ip.AddressList;
if (ipA.Length > 0)
{
Network.natFacilitatorIP = ipA[0].ToString();
Network.natFacilitatorPort = 50000;
}
C#:
using System.Net;
string masterServerUrl = "masterserver.dimerocker.com";
IPHostEntry ip = Dns.GetHostEntry (masterServerUrl);
IPAddress[] ipA = ip.AddressList;
if (ipA.Length > 0)
{
MasterServer.ipAddress = ipA[0].ToString();
MasterServer.port = 12345;
}
string connectionTesterUrl = "connectiontester.dimerocker.com";
ip = Dns.GetHostEntry (connectionTesterUrl);
ipA = ip.AddressList;
if (ipA.Length > 0)
{
Network.connectionTesterIP = ipA[0].ToString();
Network.connectionTesterIP = 10735;
}
string natFacilitatorUrl = "facilitator.dimerocker.com";
ip = Dns.GetHostEntry (natFacilitatorUrl );
ipA = ip.AddressList;
if (ipA.Length > 0)
{
Network.facilitatorIP= ipA[0].ToString();
Network.facilitatorPort = 50000;
}
EDIT:
As Leepo from wooglie.com points out, using the .Net System assembly can result in ~800K being added to your game, so this may not be an ideal solution for web games.
As an alternative, you can use a getip.php script on our server, which will resolve an url for you.
You’ll want to do it as a Coroutine, and before you make any network connection tests or poll the master server.
For example:
C#:
StartCoroutine(GetServerIPs());
while (!gotIPs)
yield return new WaitForSeconds(0.1f);
IEnumerator GetServerIPs()
{
// masterserver
WWW www = new WWW("http://www.dimerocker.com/api/getip.php?url=masterserver.dimerocker.com");
while (!www.isDone)
yield return new WaitForSeconds(0.1f);
string masterServerIP = www.data;
MasterServer.ipAddress = masterServerIP;
MasterServer.port = 12345;
// connection tester
www = new WWW("http://www.dimerocker.com/api/getip.php?url=connectiontester.dimerocker.com");
while (!www.isDone)
yield return new WaitForSeconds(0.1f);
string connectionTesterIP = www.data;
Network.connectionTesterIP = connectionTesterIP;
Network.connectionTesterPort = 10735;
// nat facilitator
www = new WWW("http://www.dimerocker.com/api/getip.php?url=facilitator.dimerocker.com");
while (!www.isDone)
yield return new WaitForSeconds(0.1f);
string natFacilitatorIP = www.data;
Network.natFacilitatorIP = natFacilitatorIP;
Network.natFacilitatorPort = 50000;
gotIPs = true;
yield break;
}
dimeRocker
Unity 3D
Unity Users Group
{ 2 comments… read them below or add one }
The DNS lookup call will add extra dll(s) of 1-2mb to the webplayer right?
For that purpose I used a www call to a php page which resolves the domains for my own masterserver.
Thanks for pointing that out, Leepo. Updated the post with the alternative.