Networking two separate PCs on the network

Hi all, I’m very very new to coding, and I’ve been trying to learn some super simple Networking stuff. I’ve been following this tutorial: http://www.palladiumgames.net/tutorials/unity-networking-tutorial/

which has been very helpful. Sadly, when I try to load a Client on my laptop and the Server on my desktop, it doesn’t work. I’ve gotten down to completing the first script (before creating a cube). I simply wanted to see if I could establish a connection between two separate computers on the same network.

I didn’t leave the connectionIp variable as 127.0.0.1. I changed it to the local IP of my desktop (192.168.1.2).

Opening two windows on the laptop and starting one as a server and one as a client connects properly even though the connectionIP variable isn’t set to local, and that machine’s IP is (192.168.1.6).

Here’s the script:

public string connectionIP = "192.168.1.2";
	public int connectionPort = 25001;
	
	void OnGUI()
	{
		if (Network.peerType == NetworkPeerType.Disconnected)
		{
			GUI.Label(new Rect(10, 10, 200, 20), "Status: Disconnected");
			if (GUI.Button (new Rect(10, 30, 200, 20), "Connect Client"))
			{
				Network.Connect(connectionIP, connectionPort);
			}
			if (GUI.Button (new Rect(10, 50, 120, 20), "Initialize Server"))
			{
				Network.InitializeServer(32, connectionPort, false);
			}
		}
		else if (Network.peerType == NetworkPeerType.Client)
		{
			GUI.Label (new Rect(10, 10, 300, 20), "Status: Connected as Client");
			if (GUI.Button (new Rect(10, 30, 120, 20), "Disconnect"))
			{
				Network.Disconnect(200);
			}
		}
		else if (Network.peerType == NetworkPeerType.Server)
        {
            GUI.Label(new Rect(10, 10, 300, 20), "Status: Connected as Server");
            if (GUI.Button(new Rect(10, 30, 120, 20), "Disconnect"))
            {
                Network.Disconnect(200);
            }
        }
    }

What am I missing? What don’t I understand yet?

Thanks!

Well, that doesn’t make much sense :wink: You said if you run s server and a client on your laptop it works. In this case, when you in fact are using “192.168.1.2” as IP, your laptop has that IP address and not your desktop. Have you simply tried to reverse your test? Start the server on the laptop and run the client on the desktop? If it works your IP addresses are the other way round.

Also what you should check is to what value is connectionIP set in the inspector. Since connectionIP is public, Unity will serialize the value so the field-initializer value in the script becomes useless. Maybe you changed it in the inspector or it was a different IP when you added the script / variable for the first time.