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());
}
}