Friday, 20 September 2019

Connect to Android App's Socket from Internet: Possible?

I am trying to develop an Android (server) app that will accept TCP connections directly from the Internet. I tried this a couple of years ago with no joy. Is this even possible?

I asked this question differently way back then, on StackOverflow and elsewhere, and never got a satisfactory answer. The answers fell into two categories:

  • No, you can't
    Most authoritative answer given: Most carriers won't route connection requests to mobile devices.

  • Yes, you can
    These answers did not provide details or examples to help me.

What I Tried

  • I can successfully get my mobile device's external IP through various means. But this is only part of the puzzle. See Note 1 below.

  • I created a ServerSocket that listened on a port (e.g., 2000). But the app would not accept connections from the Internet on this socket. Apparently, this socket was listening on the local (internal) network of the device (i.e., 192.168.1.0).

  • I was able to connect from other apps on the device (which are on the same subnet).

  • I was also able to connect through a NAT router in my shop that translated Internet addresses to my device's local net. But this doesn't help me in the field (where no router is available). See Note 2 below.

  • I tried asking AT&T customer-support-type people but I don't think they understood my question.

Notes:

    1. The devices IP address can vary with time or location, but I can always get the correct and current IP through various means (e,g., whatmyip.com). Nontheless using the current device IP doesn't work either.
    1. I can connect via WiFi because my Internet modem/router offers DHCP connections on the back side via Wifi on the device's local subnet (192.168.1.). My device has address 192.168.1.65, therefore I can connect to it without ever going through my carrier.

Maybe the answer's still the same, but I thought I'd ask again in case things have changed or somebody's got some better insight nowadays,



from Connect to Android App's Socket from Internet: Possible?

No comments:

Post a Comment