Hi, i’m working on an iOS app that starts a HTTP Server (Vapor) when it loads. This server runs on localhost (port 8081). When the app is running, other computers on the same network are able to access this webserver – This works also when connecting devices to the iPhone using Personal Hotspot.
So all of the devices on are connected to the iPhone personal hotspot, so network traffic is actually going through the device.
The problem is that some devices on the local network block any local network connections. So, for example `127.0.0.1:8081` to access the server running on the iPhone will be blocked.
I’m trying to find a way around it, and I saw that some people were able to get around this problem by using a local VPN Tunnel or Local Proxy to basically allow routing some host from a connected device over to the server running on 127.0.01:8081
I basically want to know if its possible to route a request that a connected device makes to “fakedomain.com” and be routed to “127.0.0.1:8081” server on the iOS device.
More of a comment/question … 127.0.0.1 is usually a “localhost” IP. You use that address to connect to yourself. So each device when connecting to 127.0.0.1 would connect to themselves but it sounds like what you want is for each of devices to connect to your server running on your iPhone. Your iPhone should have a “non-local” IP that other devices can use to reach it. Usually something like 192.168.1.* or 10.1.1.* etc. If you want fakedomain.com to route to your non-local IP then you need to do that at the DNS level. I’m not sure if hotspot can customize the DNS to point to a custom DNS server where you can configure fakedomain to point to the IP you want.
you’re correct, external devices would connect to the phone’s IP. The server on phone would listen to localhost.
You are correct about DNS, but through a kind of local VPN profile may get around it. That might be my only option.
If your goal is to connect multiple local devices to another local device running a server you might want look at Bonjour. It’s a protocol to allow local devices on a network to find/broadcast services. Bonjour Concepts
Doesn’t need to be a tunnel … the network that all your devices are connecting too needs to have IPs and DNS assigned via DHCP. So on your network you’d have a custom DNS server to resolve fakecomain.com to point to iPhone servers IP. But it depends on what you are trying to achieve, is this just a test environment? Or are you trying to create a product where multiple devices can connect to each other in any network environment. The the former case you just need to configure your network. In the later case you’ll need to configure some kind of multi-peer connectivity (using Bonjour), that would be the “proper” way to do it.
https://developer.apple.com/documentation/multipeerconnectivity
If you’re trying to get other devices to connect to yours over the Internet that’s whole different thing.
The setup is this:
- Tesla car, connects to phone via hotspot
- App on phone runs a http server
- Side point: If I connect my computer to phone hotspot, i’m able to access the http server using the phone’s IP address and port.
- Using the Tesla in car webrowser, I’m unable to access the web server using the phone’s IP address because the tesla in-car browser will not open the gateway address to hotspot network or any other local IP.
Here is a discussion around it: https://teslamotorsclub.com/tmc/threads/accessing-webpage-on-gatewas-ip.158147/
I see so it looks like there is a security constraint on the Tesla browser that prevents it from hitting local IPs. The page you link suggested using a 3rd device as the WiFi host (i.e. RPI). I think that could work. But it’s all a bit of a hack. I think the proper way to get this to work would be to move your server out of the iPhone and deploy it somewhere external that the Tesla browser can reach. You’ll need to change your iPhone app to also interface with that server to pull/push whatever data it needs. If you do it that way then you don’t even care about WiFi, it would work on cellular too.
Correct, but somebody was able to get around the limitation using a vpn on the phone.
On this project: https://teslamirror.com/
On their FAQ, its mentioned:
4 Why does this TeslaMirror App need a VPN service? Is there any privacy issue with it?About the need for VPN, it is mainly because Tesla blocks all of the normal private LAN segment. So, the virtual IP address is used to bypass the Tesla network limitation. The VPN tunnel is not connected to any public server. For the VPN tunnel, one side is the iOS/Android device to be mirrored, another side is the Tesla car. There is a web server running on the iOS device with a virtual IP 240.3.3.3 (Android with 3.3.3.3 IP address). This web server is not available for public Internet access. There are only Tesla car and the phone, no middle server running on the Internet. There is no privacy issue with it.
I’d like to know how to achieve that. I think its most convenient given the circumstances.
I disagree, needing a VPN is less convenient for a user. What other services/app do you know have a requirement for a VPN? Having an external server hosting it all is the most convenient for the user. It’s less convenient for a developer though because you need to build extra infrastructure/authentication etc. to support it.
But a VPN tunnel could also solve the problem but you need to run a VPN server somewhere. Based on the description you posted they must be running the VPN server on the phone (they state that the tunnel is not using a public server) but what’s confusing is how TeslaMirror managed to configured the network to transparently connect to the VPN over hotspot. I could imagine there are ways to get this to work on Android, but on iOS I can’t imagine you’d be able to configure a system level feature like hotspot from within an app.
There’s some hackery going on here, it’s not going to be straight forward I imagine.
Yeah so I’m seeing some API’s that might make this possible like:
https://developer.apple.com/documentation/networkextension/nehotspotnetwork
https://developer.apple.com/documentation/networkextension/personal_vpn
But you’ll still need a VPN server running on your phone.
Think this is actually going to be more complicated then pushing your server out externally. Thinking about the requirements of TeslaMirror (mirroring another screen) it’s not surprising they wanted to do this all locally (latency needs to be good). If you’re not building something that requires very low latency I wouldn’t use the same model that TeslaMirror is doing. I’m sure it was challenging for them to implement this solution.