- Home /
Strange IP and Port when using Network.Connect()
I'm trying to set up a simple client-server system in my Unity project. In my server script I have a Network.Connect(ip, port) line which passes the IP 127.0.0.1 and port 8000 for testing. When I start my game, it crashes with this error:
The connection request to 67.225.180.24:50005 failed. Are you sure the server can be connected to?
I ran a Whois on the IP from the error and it belongs to Unity Technologies. I don't want to use Photon or a Master Server for my game (which I think this belongs to), I just want to use IP connections. Does anyone know why it is trying to connect to the Master Server (I don't think I have any Photon code running) and does anyone know how to fix this?
Server script:
using System.Collections;
using UnityEngine;
public class NetworkManager : MonoBehaviour
{
private int port = 25565;
private void StartServer()
{
Network.InitializeServer(4, port, true);
}
void OnServerInitialized()
{
SpawnPlayer();
}
void OnGUI()
{
if (!Network.isClient && !Network.isServer) {
if (GUI.Button (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 25 - 50 + 5, 200, 50), "Start Server"))
StartServer ();
if (GUI.Button (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 25 + 50 + 5, 200, 50), "Join localhost"))
JoinServer ("127.0.0.1", port);
} else if (Network.isServer) {
GUI.Label (new Rect (5, Screen.height - 20, 50, 20), "Server");
} else if (Network.isClient) {
GUI.Label (new Rect (5, Screen.height - 20, 50, 20), "Client");
}
}
private void JoinServer(string ip, int port)
{
Debug.Log ("Attempting to join " + ip + " on port " + port + ".");
//Network.Connect(ip, port);
Network.Connect("127.0.0.1", 25565);
}
void OnFailedToConnect()
{
Debug.Log ("Failed to connect to server.");
GUI.Label(new Rect(Screen.width / 2 + 100, Screen.height / 2 - 25 + 50 + 5, 200, 50), "Failed, you fucking dingus.");
}
void OnConnectedToServer()
{
Debug.Log("Server Joined");
SpawnPlayer();
}
public GameObject playerPrefab;
private void SpawnPlayer()
{
Network.Instantiate(playerPrefab, new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y, this.gameObject.transform.position.z), Quaternion.identity, 0);
}
void Update()
{
Debug.Log(Network.TestConnectionNAT().ToString());
Debug.Log(Network.TestConnection().ToString());
}
}
Answer by Bunny83 · Jun 11, 2015 at 11:32 AM
Well, you passed "true" to "useNAT" which will require a Masterserver as NAT punchthrough requires the facilitator (which is part of the Masterserver). If you don't want to use a MasterServer you should set it to false.
Network.InitializeServer(4, port, false);
I can't guarantee that Unity won't try to connect to the MasterServer. However when setting useNAT to true you definately are using the MasterServer.
BTW: Network.TestConnectionNAT and maybe even Network.TestConnection are using the MasterServer as well.
Okay, so I set it to !Network.HavePublicAddress() as I saw somewhere else (which equates false, by the way) and it seems to work. After I fully test it, I'll mark this as correct.
Your answer
Follow this Question
Related Questions
Photon Cloud Networking: OnPhotonSerializeView Not Firing 9 Answers
Photon Unity Networking (Viking Demo) Error: Argument is out of range. 1 Answer
Networking already instantiated assets 1 Answer
Update position via state syncronization results in weird movement. 0 Answers
Photon Virtual Joystick won't work after another player has joined the network...? 1 Answer