Simple networking - Sending string over network?

Ok, so I managed to build a simple network interface that tells whenever you’re client or a host, but it only works in localhost (web player and standalone). I tried building a android version with my PC’s global IP, but it doesn’t work. Here’s my code:

`

public string connectionIP = "127.0.0.1";
public int connectionPort = 25001;
public Text displayText;

void Start()
{
	displayText.text = "";
}

void OnGUI() {
	
	if (Network.peerType == NetworkPeerType.Disconnected) 
	{
		GUI.Label (new Rect (10, 10, 200, 20), "Status: Disconnected");
	}

	if(GUI.Button(new Rect(10,70,120,30), "Client Connect"))
	{
		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, 200, 20), "Connected as client");
	}

	if(GUI.Button(new Rect(10,30,120,20),"Disconnect"))
	{
		Network.Disconnect(200);
	}
		
}

void Update()
{
	if (Network.isClient) 
	{
		displayText.text = "you are a client";
	}
	if (Network.isServer) 
	{
		displayText.text = "you are a host";
	}
}

}

`

Uhm, there is no thing like a “global IP”. In your actual code you’re using localhost. You did not mention how you Android device is connected to your PC. Are they in the same LAN / WLAN? Did you use the LAN address? If you try to connect your android over the internet you would need to use the IP of your router and you have to port-forward the port 25001 in your router settings in order to be able to connect to your PC from the internet.

Typical LAN / WLAN addresses are:

192.168.x.x
172.16.x.x
10.x.x.x

Those are private IP addresses which are never routed through the internet. So if you actually use one of those addresses, make sure both (server and client) are connected to the same network.

Note: Some routers don’t allow a local loopback connection. That means if you have implemented a port-forwarding rule in your router, any peer on the same network can’t use the public router IP to connect to your server, but anybody else on the internet can. This makes it difficult to test if you’re reachable from the internet or not.