Recently Started Learning how to do Net Code VIA tutorial, and the code seems to be working right. I can join the server if I open two instances of the game.
However, my friend in another state and I tried to connect to the same server and it wouldn’t allow us to.
Sadly I didn’t put any debugs in for connection while we were testing.
It shows the server after either of us created it but we cannot join.
Here’s The Script… Hopefully one of you can take a quick glance at it and see if and what is missing.
var gameName:String = "JuiceBox Trosity";
var playerPrefab:GameObject;
var spawnObject:Transform;
private var btnX : float;
private var btnY : float;
private var btnH : float;
private var btnW : float;
private var refreshing:boolean;
private var hostData:HostData[];
function Start(){
btnX = Screen.width * 0.09;
btnY = Screen.width * 0.09;
btnH = Screen.width * 0.1;
btnW = Screen.width * 0.1;
}
//Starts Server//
function startServer(){
Network.InitializeServer(8, 25001, !Network.HavePublicAddress);
MasterServer.RegisterHost(gameName, "JuiceBoxTrocityTest", "This is a Networking Server Test");
}
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);
}
//message logs//
function OnServerInitialized(){
Debug.Log("Server Initialized!");
spawnPlayer();
}
function OnConnectedToServer(){
spawnPlayer();
}
function OnMasterServerEvent(mse:MasterServerEvent){
if(mse == MasterServerEvent.RegistrationSucceeded){
Debug.Log("Registration Succeeded");
}
}
//GUI
function OnGUI(){
//Creates Gui Boxes//
if(!Network.isClient && !Network.isServer){
if(GUI.Button(Rect( btnX, btnY, btnH, btnW),"Start New Server")){
Debug.Log("Starting Server");
startServer();
}
if(GUI.Button(Rect( btnX, btnY * 1.2 + btnH, btnH, btnW),"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*);*_
* }*
* }*
* }*
* }*
}