JMRboosties
JMRboosties

Reputation: 15740

Is there any port forwarding I need to do when hosting a server locally for Android app use?

So I wanted to test my app on an actual android device. I've debugged it on the virtual device and it's working smoothly, but I want it to be able to work on actual phones now for debugging and whatnot as well. I changed the IP I use to access a locally hosted server from 10.0.2.2 to my own. So every time I call up the server which my app queries, it went from:

HttpPost httpPost = new HttpPost("http://10.0.2.2/pagemyappwants.php");

to

HttpPost httpPost = new HttpPost("http://76.blahblah.etc/pagemyappwants.php");

the latter being my own computer's IP, which I have used to run remotely accessed servers in the past. I've tested this for the wamp/apache server I'm running, and using this IP you can access the php pages from other computers. However, when I try to use my app, the app freezes up for a few minutes, then moves on as if the task was completed, but when checking the mysql db which would log a change/addition made via the app, nothing has happened.

So in summary, is there any port forwarding I need to do in order for a locally hosted server for android use to work? Or anything else, for that matter, which would fix this problem? Thank you.

Upvotes: 1

Views: 446

Answers (1)

Ollie C
Ollie C

Reputation: 28509

Your description doesn't seem very clear, but if I understand correctly that your application is making an HTTP call over the public net to your own PC, via your public IP address, then the only port that needs opening is port 80 (assuming non-secure HTTP).

You say "the app freezes up for a few minutes, then moves on as if the task was completed". Do you actually mean minutes, or just a lot of seconds? If minutes, that doesn't sound right as the HTTP timeout is not that long.

If it were me I'd want to:

  • Get some tracing/debugging going on the HTTP call to see EXACTLY what is happening, and particularly what exception is being thrown, or what result is coming back. It sounds like it's timing out, but you're not mentioning an exception, which leads me to think your app is now handling exceptions correctly.

  • I'd try accessing the HTTP URL using the browser on the device, to see if it actually has access to it.

  • Check the port forward. It's not usual for routers to be configured by default to handle incoming HTTP requests as it creates security risks. If you have previously set that up, and it is now not working, is it possible that the port forward from the router to your PC is failing as your PC has a different IP address?

Upvotes: 1

Related Questions