The following worked perfectly when compiled under older versions of B4J, however, seems to be ineffective with current B4J Version 9. I was using it to connect to a Mosquitto MQTT broker without issue. However, I now have a situation where existing B4J MQTT Clients (compiled under older versions of B4J) are connecting to the broker BUT a new instance (exactly the same code) compiled under B4J Version 9 (today) gets rejected.
B4X:
'Depends on JavaObject and jNet or Net libraries
Sub TrustAll (mo As MqttConnectOptions)
Dim SSLContext As JavaObject
SSLContext = SSLContext.InitializeStatic("javax.net.ssl.SSLContext").RunMethod("getInstance", Array("TLS"))
Dim tm As CustomTrustManager
tm.InitializeAcceptAll
SSLContext.RunMethod("init", Array(Null, tm, Null))
Dim jmo As JavaObject = mo
jmo.RunMethod("setSocketFactory", Array(SSLContext.RunMethod("getSocketFactory", Null)))
End Sub
Has anyone else noticed this? Any ideas as to how to rectify or prove otherwise??
Open to any/all suggestions. I may well be entirely wrong in relation to this so apologies in advance!
I just tried it with version 8.50 and it connected to the Mosquitto broker first time as expected. I have not changed anything other than rolling back to Version 8.50. I'll try it now with 8.9. Thank you.
I downloaded 8.9 from your link - thank you - and my code connected to the Mosquitto broker as expected (correctly, first time). So, from what I've observed, my code successfully connects to the external broker on B4J versions 8.5 and 8.9, but not on V9.0. If its not related to the B4J version - I'm totally confused (however, that's not a new thing). Any assistance appreciated. Thank you.