Problem:
By default, Android has only one active Network, so when you have your other device connected to your phone over Wi-Fi (IoT, Dashcam, whatever, obviously with no internet), your Android Cellular got unavailable for the App. If you switch to Cellular (eg ConnectivityManager.bindProcessToNetwork
), Wifi is not available anymore for any http://10.XX.XX.XX
requests to device.
Adding more complexity: You technically can ping second network, but simply doing Network.openConnection(...)
to WiFi network is not enough, cause I have FFMPEG running on low level, that needs a constant access to WiFi device, with no control over when it will happen and how, it's a low level process.
What I really need is STABLE RE-ROUTING OF ALL THE TRAFFIC COMING TO HTTP://10.XX.XX.XX TO WIFI DEVICE. Am I asking a lot? Task seems trivial on the paper, so once all the traffic to this particular IP gets re-routed to WiFi, I'm ok to send everything else to Cellular.
What I did so far:
- Bound all the traffic to Cellular by default
- Created VPNService to catch all the traffic to 10.XX.XX.XX port via
VPNService.Builder().addAddress(...).establish()
so I gotParcelFileDescriptor
to work with. How can I send all this catched traffic to WiFi network now, and get the entire flow back to client? Special notes to anyone who will advice creating TCP Socket for this IP address or usingNetwork.getSocketFactory().createSocket(...)
to get specific socket bound to WiFi: I need it STABLE and ALIVE. DeprecatedrequestRouteToHost
is not working anymore, please don't advice those old & outdated stuff, I killed a LOT of my time to test it out. I don't need to close my connection and open it over and over again, I don't need to work for 4 seconds straight and then drop, and then re-run it again. I'm looking for solution which is: - stable
- alive for the entire session of the App
- simply flows the data from VpnService to Wifi and sends it back to requesters
- or maybe you know another, simple and modern way to use the latest Android SDK and perform it in a short and elegant way. Huge thanks to any of you in advance for the time you spent reading that post.