Sub Socket1_connected(succ As Boolean)
If succ = False Then
Msgbox(LastException.Message, "Error connecting")
Return
End If
The error message is: "android.system.ErrnoException: connect failed: EINVAL (Invalid argument)"
Note: This is NOT a java.net.Socket.TimeoutException !
then it works ! (which means, the EINVAL error doesn't occur any more)
So my question is: Why do link-local IPv6 addresses (FE80::...) fail in Android/B4a ?
(btw: in the devices "settings-> connections" a link-local address is correctly shown)
The issue you're encountering with link-local IPv6 addresses (starting with FE80:...) in Android/B4A likely stems from how Android handles network connections and permissions for socket operations.
Here are a few points to consider:
Scope Identifier Requirement: When using a link-local IPv6 address (FE80::...), it's crucial to include the scope identifier for the network interface. The scope identifier specifies which interface to use for the connection. In some environments, including the scope identifier (e.g., %wlan0 for Wi-Fi) is necessary to ensure the correct interface is used.
Example:
Socket1.Connect("FE80::XXXX:YYYY:ZZZZ:RRRR%wlan0", 2222, 10000)
Replace wlan0 with the actual interface name of your Wi-Fi connection. This ensures Android knows through which interface to attempt the connection.
Android Security Policies: Android has stringent security policies regarding network operations. It might restrict or require specific permissions or configurations for certain types of network connections, especially when dealing with link-local addresses. Ensure your app has the necessary network permissions declared in the manifest (<uses-permission android:name="android.permission.INTERNET" />).
Error Handling: The EINVAL error (Invalid argument) can occur for various reasons related to incorrect arguments passed to the socket connection function. Double-check that the format of the IPv6 address and the inclusion of the scope identifier are correct.
Testing Environment: Consider testing your app on different Android versions and devices. Network behavior, including support for IPv6 link-local addresses, can vary depending on the device manufacturer and Android version.
In summary, ensure you include the correct scope identifier when using link-local IPv6 addresses in your socket connections on Android. This identifier specifies the network interface and helps Android route the connection correctly. Also, adhere to Android's network security policies and permissions to avoid runtime errors related to network operations.
Thank you very much, @LucaMs . Your answer #1 is the solution. Adding %wlan0 to the ip-address made the code working.
But here is the next issue: this trick does NOT work with B4A's OkHttpRequest. Any idea how to solve that ???
Thank you very much, @LucaMs . Your answer #1 is the solution. Adding %wlan0 to the ip-address made the code working.
But here is the next issue: this trick does NOT work with B4A's OkHttpRequest. Any idea how to solve that ???
Sorry @LucaMs , but this time ChatGPT serves more confusion than solution:
Fact is:
1. in B4A OkHttpClient has no member CreateRequest as one can read here
2. This code does NOT work:
B4X:
Dim hc As OkHttpClient
hc.Initialize("hc")
Dim req As OkHttpRequest
req.InitializeGet("http://[FE80::XXXX:YYYY:ZZZZ:RRRR%wlan0]:1234/abcd.htm")
hc.Execute(req, 3)
....
Error in log is: java.lang.IllegalArgumentException: Invalid URL host: "[fe80::XXXX:YYYY:ZZZZ:RRRR%wlan0]"
Any more ideas ???
ok, i deleted MsgBox from my code (although i don't know why) and i use OkHttpUtils2, Version 3.02, internal lib.
But fact is, that this code also doesn't run:
B4X:
Dim hj As HttpJob
hj.Initialize("",Me)
hj.Download("http://[FE80::AAAA:BBBB:CCCC:XXXX%wlan0]")
Wait for (hj) JobDone(hj As HttpJob)
If hj.Success Then
Log(hj.GetString)
label1.Text = hj.GetString
Else
label1.Text ="Error"
End If
the "hj. Download" line throws this error: Invalid link: http://[fe80::AAAA:BBBB:CCCC:XXXX%wlan0]
which appears to be same the other libs throw (OkHttpClient,OkHttpRequest...)
So there seems to be a very basic bug in all these B4A libs.
The fact is that I already told you the answer long ago - the host name isn't managed by B4A in any of these libraries. The host name is handled by the OS.
@Erel , you wrote in post #2 long ago: "The address is passed as is to the native API".
That holds true for the Network library, but is not true for OkHttpUtils2, OkHttpClient, OkHttpRequest... These libraries obviously interpret the NEEDED so called scope (i.e. "wlan0", separated by a "%", see LucaMS post #3) as error and throw an error.
That's probably the simple reason, why all these B4A libraries fail and should be simple to correct !
OkHttpUtils2 is based on the very popular OkHttp. OkHttp uses the native API for the network communication.
Thread is locked because I don't like your attitude.