Unity tcp_client only working on localhost


I am using Unity 2018.1.5 to connect to my python server through TCP. I can only manage to connect when running client & server on the same machine and I am using port 50000. If I change the port to pretty much anything else OR if I try to run the unity executable on any other device on the network, I get no connection.

I have tried using my local ip “”, my public IP and even a domain name. I have opened the correct ports on my router, and firefox/chrome can connect to my server from any device in the network without a problem.

So, the way I see it, unity is doing something that prevents other ports from working and cannot connect unless the server is running on the same machine. (I should mention that when running on the server machine, “localhost”, my local ip and my public ip all seem to work with unity).

The code I am using:

public String host = "localhost";
public int port = 50000;
            tcp_socket = new TcpClient(host, port);
            net_stream = tcp_socket.GetStream();
            socket_writer = new StreamWriter(net_stream);
        catch (Exception e)
        	// Something went wrong
            Debug.Log("Socket error: " + e);

Figured it out, I was using the public String variable “host” to connect, and I kept changing its value in the script (which is the default value), but it already had a set value in the editor (namely “localhost”) so it wasn’t really updating and unity was always trying to connect to localhost.

A simple “Debug.Log(host)” would have saved me the trouble…