- Home /
Unity Master Server Connect to own Server won't work
Hi everyone!
A standard Peer to Peer connection worked for me most of the time but for my current project I need the Unity Master Server. So I just started using it and the connection seems to work well. I'm able to create a server, register it and get the server list. But when I want to connect to the server I created I get the following error: "The connection request to 192.168.x.xxx:3000 failed. Are you sure the server can be connected to?"
I have to mention that I just started the Play Mode in Unity and ran a server. While being in this play mode session I refreshed host list and wanted to connect to exactly the server I created just a few seconds before.
So is it maybe impossible to connect to the server I'm running? That would be bad because I want to create 1vs1 sessions where the creator is the host of the match.
I also see that the IP displayed in my console is my LAN IP. But all in all I want to connect from mobile devices (connection allowed to both WLAN and mobile internet).
Again: Everything else works. The connection to the master server works fine and creating a server won't throw me an error. Just using the "Network.Connect"-Function throws the message above to my console.
Maybe I don't understand something regarding networking games so I'm very thankful for your help in advance!
Here is my connection code:
void Awake(){
Instance = this;
// Set IP and Port of the Master Server
MasterServer.ipAddress = this.MasterServerIP;
MasterServer.port = this.MasterServerPort;
// Facilitator is neccessary for NAT punchthrough
Network.natFacilitatorIP = this.MasterServerIP;
Network.natFacilitatorPort = this.FacilitatorPort;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if(GUILayout.Button("Launch Server")){
LaunchServer();
}
if(GUILayout.Button("Refresh")){
print ("Pressed Refresh");
RefreshHosts();
}
if(loadingServerList){
GUILayout.Label("Loading...");
}
else{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200f), GUILayout.Height(200f));
HostData[] hosts = MasterServer.PollHostList();
for(int i = 0; i < hosts.Length; i++){
if(GUILayout.Button(hosts[i].gameName, GUILayout.ExpandWidth(true))){
print("Have public adress? " + Network.HavePublicAddress());
Network.Connect(hosts[i],);
}
}
if(hosts.Length == 0){
//print ("No Servers");
GUILayout.Label("No Servers running");
}
GUILayout.EndScrollView();
}
}
void LaunchServer(){
print("Have public adress? " + Network.HavePublicAddress());
Network.InitializeServer(2, this.MasterServerPort, true);
MasterServer.RegisterHost(this.GameType, "TestArenaServer", "thisIsATest");
}
void OnServerInitialized(){
Debug.Log ("Server initialized");
}
void OnConnectedToServer(){
print ("Connected to Server");
NetworkLevelLoader.Instance.LoadLevel("MPArena");
}
void RefreshHosts(){
loadingServerList = true;
print ("Refreshing from Master Server at IP: " + this.MasterServerIP + ", Port: " + this.MasterServerPort);
MasterServer.ClearHostList();
MasterServer.RequestHostList(this.GameType);
}
void OnMasterServerEvent(){
// received Host list
print ("Finished!");
loadingServerList = false;
}
Best regards
Mischaal
Your answer
Follow this Question
Related Questions
Proxy Server 0 Answers
Is the master server down? 0 Answers
Unity master server down? 0 Answers
Do RPC calls get sent through Master Server or directly to the other client? 2 Answers
Network.Connect() won't connect? 0 Answers