Problem with basic networking...

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 :frowning:

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

sounds like you oughta try using the master server to find the correct IP rather than hard-coding it. I generally find it’s a bit safer.

http://docs.unity3d.com/Documentation/Components/net-MasterServer.html

First make sure your server uses the function RegisterHost()

then have the client query the master server for available server’s and pick up the IP from it that way.

(In theory your code is fine, but in my limited networking ventures, the master server has been more reliable for me for this kind of issue, though im still not sure why).