Android Question java.net.SocketException: Machine is not on the network

RJB

Active Member
Licensed User
Longtime User
I have the same problem as in https://www.b4x.com/android/forum/t...achine-is-not-on-the-network-response.117816/.
i.e. after reconnecting to a router using Andoid 10+ I get the error: (SocketException) java.net.SocketException: socket failed: ENONET (Machine is not on the network).
I've found a potential workaround on Github https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/185 as follows:
Can anyone help with how to implement this in B4A?
Thanks
 

drgottjr

Expert
Licensed User
Longtime User
i've always wondered what react-native was, but i was too lazy to research it. now i know.

the WifiManager.forceWifiUsageWithOptions() method referred to in your post is not android's
even though it might appear familiar. it is from a project built using react-native. it may or
may not provide some function that android didn't implement. (or perhaps android has buried
it in its connectivitymanager class).

although the method is not found in android code, most of the code in the method is.
at first i thought it might be possible to borrow the method and paste it as inline java in
your app. but on closer scrutiny, it makes use of react-native's implementation of Promise,
which may or may not be the same as java's. and if you try to use their implementation, you
would have to import react-native packages.

if someone had enough time and interest, they could study the method's code to see exactly
what it does that android doesn't do. then it could be recoded using all android code. what
i saw did reveal much beyond a lot of checking whether or not there was a connection.

another option would be to build that project with eclipse or intellij and wrap it so that the
method could be called directly from b4a (or with a javaobject if the project weren't wrapped).
but who knows what conflict there might be. there is a lot of overlapping of stuff that might
cause our compiler to balk and possibly a lot of time needed to make everybody happy.
react-native is, effectively, a competing platform to what we use.
 
Last edited:
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Well I'd never heard of react-native!! I assumed that " WifiManager..... will trigger Android to recheck" was referring to Android wifimanager functionality.
Looks like another dead end!
Thanks for pointing that out.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
yeah, sorry. think of it like b4a without the "b". you code in java, and you build, among others, android apps. in this case, it uses android's wifimanager class to do what it does. if we knew exactly what it does, we could re-write it without the react-native bits. after all, the author wrote it with the react-native bits to handle some aspects. but he used android classes just like we do. he may or may not have figured out how to deal with your issue. i mean, we really don't know if it would have worked, and
whatever he figured out probably has nothing to do with react-native. he just chose react-native as his development platform, but he used android classes. we use b4a as our platform, with android classes.
 
Reactions: RJB
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…