I am attempting to create an AR unity app that I deploy to android that allows me to update the position of a 3d object relative to an anchor. I cannot get my unity app client to my python server due to connection refused. I have tried setting the python server ip to my wifi ip address, 0.0.0.0, and 127.0.0.1. While respectively setting the client connection ip address to the same. No matter what I get connection refused. Can someone tell me the proper way to do this please?
Networking, UnityWebRequest, WWW, Postman, curl, WebAPI, etc:
And setting up a proxy can be very helpful too, in order to compare traffic:
This makes no sense You should look up how network sockets work. When you create a server, you can bind your server socket to a certain IP, so it only reacts when the incoming packets were send to that specific address. “127.0.0.1” is not a real IP address. It’s the local loop back and that’s true for ALL systems and machines. Since you said you have a python server (that probably runs on your PC) and an Android app, they are two separate machines. So 127.0.0.1 is out of the question.
I’m not sure what you mean by your “wifi” IP address. When you mean the local IP that your PC got from your router, that probably should work. However when you mean your public WAN address, that would not work. Your PC doesn’t have that address, so you can not bind to this address and you will never receive a packet for that destination address.
That’s why it’s common to bind your server to “0.0.0.0” which means it accepts connection requests regardless of the destination address as long as it arrives at your machine.
Of course the client side is a different story. The client has to connect to a specific endpoint. When you test inside your local network, that would be the local IP of your PC that is running your server. There are no other options. When you want to connect from the internet and you are behind a NAT router (which is pretty normal nowadays) you would need to setup a port forwarding rule inside your router to your PC. So when someone connects to your public IP on a certain port, that request will be forwarded to your PC.
Note that some routers prevent local clients to connect to your own public WAN address for security reasons. Though in some routers you can disable it and others don’t have this at all. Also note that some routers don’t allow communication between wifi devices and only provide internet access for each one. My Fritz box has a checkbox to specifically allow communication between wlan clients.
So many potential obstacles.
So to sum up:
- Bind your server to “0.0.0.0” to accept any connection on your server side that actually reaches your server on that port
- Make sure your android device can actually reach your PC and that you use the correct IP to connect to. Using something like WireShark on your PC might help to see if any connection request actually reaches your PC.
Also, make sure your python server actually works. Can you connect to it from a client on your own PC?