Hey guys,
I’m doing some simple networking, with a master server setup. Do players need to be outside of a router to run a server? I keep getting this error when someone else tried to join my game:
Receiving NAT punchthrough attempt from target 612490390023824356 failed
This is my code :
var playerPrefab : GameObject;
var gameName : String = "TestGameName";
private var refreshing : boolean;
private var hostData : HostData[];
private var btnX : float;
private var btnY : float;
private var btnW : float;
private var btnH : float;
function Start () {
btnX = Screen.width * 0.05;
btnY = Screen.width * 0.05;
btnW = Screen.width * 0.1;
btnH = Screen.width * 0.1;
}
function StartServer () {
Network.InitializeServer(32, 25000, true);
MasterServer.RegisterHost(gameName, "Test Game", "This is a tutorial game");
}
function RefreshHostList () {
MasterServer.RequestHostList(gameName);
refreshing = true;
}
function Update () {
if (refreshing) {
if (MasterServer.PollHostList().Length > 0) {
refreshing = false;
Debug.Log(MasterServer.PollHostList().Length);
hostData = MasterServer.PollHostList();
}
}
}
function SpawnPlayer () {
Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
}
function OnServerInitialized () {
Debug.Log("Server initialized!");
SpawnPlayer();
}
function OnConnectedToServer () {
SpawnPlayer();
}
function OnMasterServerEvent (mse : MasterServerEvent) {
if (mse == MasterServerEvent.RegistrationSucceeded) {
Debug.Log("Registered server!");
}
}
function OnGUI () {
if (!Network.isClient && !Network.isServer) {
if (GUI.Button(Rect(btnX, btnY, btnW, btnH), "Start Server")) {
Debug.Log("Starting Server");
StartServer();
}
if (GUI.Button(Rect(btnX, btnY * 1.2 + btnH, btnW, btnH), "Refresh Hosts")) {
Debug.Log("Refreshing");
RefreshHostList();
}
if (hostData) {
for (var i:int = 0;i < hostData.length; i ++) {
if (GUI.Button(Rect(btnX * 1.5 + btnW, btnY * 1.2 + (btnH * i), btnW * 3, btnH * 0.5), hostData*.gameName)) {*
_ Network.Connect(hostData*);_
_ }_
_ }_
_ }_
_ }_
_}*_