Add targetHostIp option, support concurrent STA in Android #432
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Android 12 introduced WiFi STA/STA concurrency, which allows supported devices to connect to more than one Wi-Fi network at the same time.
For example, when connecting to an IoT device, an Android phone can be connected concurrently to both:
The primary internet-providing Wi-Fi network
A local-only IoT Wi-Fi network
From the Android documentation:
Problem
In the current implementation (master branch), the wifiOnly option routes requests through the Wi-Fi interface. However, with STA/STA concurrency there may be multiple Wi-Fi interfaces, and Android can choose either of them. This can cause requests to be routed to the wrong network.
Solution
This PR introduces a new option, targetHostIp, which explicitly specifies the IP address of the device you want to send the request to. This ensures requests are routed to the correct interface when multiple Wi-Fi connections are active.
References
Similar functionality has been implemented in other libraries, e.g.: Rapsssito/react-native-tcp-socket#193