I am new to networking in Unity and therefore tried this basic code from a Youtube tutorial. It works like a charm locally with two instances on the same computer. But as soon as I try online with 2 instances on 2 different computers (I even tried from my android phone as well), I get no reaction from the script.
The IP in the script is my external IP. Locally it works… as well as 127.0.0.1 ofc!
I think my problems has to do with the port (here I chose 25001). I tried a few different ones.
I also tried port forwarding on my router - opening port 25001 UDP (and TCP) to traffic.
Absolutely nothing works
Now I don’t know how to continue - this was my entry point as I’m not much of a coder and kinda learn as I go along.
Here’s the code:
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour {
public string IP = "212.45.114.171";
public int Port = 25001;
void OnGUI()
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
if(GUI.Button(new Rect(100,100,200,50),"Start Client"))
{
Network.Connect(IP,Port);
}
if(GUI.Button(new Rect(100,150,200,50),"Start Server"))
{
Network.InitializeServer(10,Port);
}
}
else {
if(Network.peerType == NetworkPeerType.Client)
{
GUI.Label(new Rect(100,100,200,50),"Client");
if(GUI.Button(new Rect(100,150,200,50),"Logout"))
{
Network.Disconnect(250);
}
}
if(Network.peerType == NetworkPeerType.Server)
{
GUI.Label(new Rect(100,100,200,50),"Server");
GUI.Label(new Rect(100,150,200,50),"Connections: " + Network.connections.Length);
if(GUI.Button(new Rect(100,200,200,50),"Logout"))
{
Network.Disconnect(250);
}
}
}
}
}