Network connection not working!

Hi everyone. I have created this script which is attached to an empty object in my scene. It uses the master server to connect. When I press the connect button it prints “yay” but doesn’t connect. I am trying to connect to an executable (Mac) and the unity editor… Code:

var serverPort : String="25000";
var networkGameName : String;
private var hostNumber : int;
private var hostData: HostData[];

function Start (){
	MasterServer.RequestHostList("GameType");
}

function Update (){
	if(MasterServer.PollHostList().length>0){
	hostData=MasterServer.PollHostList();
	print(hostData[0].gameName);
	}
}

function OnGUI (){ 
	if(Network.peerType == NetworkPeerType.Disconnected){
	networkGameName=GUI.TextField(Rect(5, 30, 150, 20), networkGameName, 20);
	if(GUI.Button(Rect(5, 5, 150, 20),"NewServer")){
		Network.InitializeServer(32, parseInt(serverPort), false);
		MasterServer.RegisterHost("GameType", networkGameName, "Comment");
	}
	
	if(GUI.Button(Rect(200, 40, 30, 20),"<") && hostNumber>0){
		hostNumber--;
	}
	if(GUI.Button(Rect(235, 40, 30, 20),">") && hostNumber<10){
		hostNumber++;
	}
	
	if(hostData){	
	for(var element : HostData in hostData) {
        var tmpIp : String = "";     	
        tmpIp = element.ip[hostNumber] + " ";      	
        Debug.Log(element.gameName + " ip: " + tmpIp + ":" + element.port);
        Network.natFacilitatorIP = tmpIp;
   	 	Network.natFacilitatorPort = element.port;
    }  
    
	if(GUI.Button(Rect(200,5,200,30), hostData[hostNumber].gameName)){
		Network.Connect(tmpIp, hostData.port);
		print("yay");		
		}
	}else{
		GUI.Button(Rect(200,5,200,30), "Can't Find Any Games!");
	}
}	
	if(Network.peerType != NetworkPeerType.Disconnected){
		if(GUI.Button(Rect(5, 5, 150, 20),"Disconnect")){
			Network.Disconnect();
		}
	}
}   

-------------------Can you see anything wrong?--------------------

Go to Edit/Project Settings/Network and set Debug Level to Full.
Monitor on console what is happening when you connect() and you will get your answer.
Remember to set Run In Background in Edit/Project Settings/Player because when you connect the client, the server is paused.
If it does not connect, shows the console log here .

MasterServer is to facilitate the connection. So, use it to connect.

This is the function:

static function Connect (hostData : HostData, password : String = “”) : NetworkConnectionError

Just use the HostData: Network.Connect(HostData) like this:

if(hostData){  

// for(var element : HostData in hostData) {
// var tmpIp : String = “”;
// tmpIp = element.ip[hostNumber] + " ";
// Debug.Log(element.gameName + " ip: " + tmpIp + “:” + element.port);

// Network.natFacilitatorIP = tmpIp;
// Network.natFacilitatorPort = element.port;
// }

if(GUI.Button(Rect(200,5,200,30), hostData[hostNumber].gameName)){
   Network.Connect(hostData[hostNumber]);
   print("yay");     
   }

}else{
   GUI.Button(Rect(200,5,200,30), "Can't Find Any Games!");
}

And the code at Update() and Start, try to put it in a button or in a function called by a button, may be a button named Refresh:

function RefreshHosts(){   
	MasterServer.RequestHostList("GameType");

	yield WaitForSeconds(1);

    if(MasterServer.PollHostList().length>0){  
		hostData=MasterServer.PollHostList(); 
		print(hostData[0].gameName); 
    }

}