Worklight method for checking connection

后端 未结 1 919
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 19:05

The project im working on, they would like active server connection detection before each call.

Im trying to find out if its better to use: WL.Device.getNetworkI

相关标签:
1条回答
  • 2021-01-14 19:29

    getNetworkInfo API can be used to verify whether device currently has an internet connectivity.

    As for WL server connectivity there is only one way to verify that server is accessible and this is by issuing a request to WL server and verifying whether it succeeded. However this is not right way to go. Every WL server invocation API, e.g. WL.Client.connect(), WL.Client.login(), WL.Client.invokeProcedure(), has onSuccess and onFailure callbacks. Use them to verify whether server connectivity was successful or not.

    Technically, even if you do additional request like WL.Client.connect() before making a real request it will not give you 100% assurance that the real request will succeed.

    In addition you may want to utilize WORKLIGHT_IS_CONNECTED and WORKLIGHT_IS_DISCONNECTED events which are fired each time last WL server invocation status toggles success<->failure. Check out the offline training module at Worklight Getting Started page.

    0 讨论(0)
提交回复
热议问题