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!