用于检查连接的Worklight方法 [英] Worklight method for checking connection

查看:78
本文介绍了用于检查连接的Worklight方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

项目正在进行中,他们希望在每次通话之前检测有效的服务器连接。

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

我试图找出它是否更好用:
WL.Device.getNetworkInfo:isNetworkConnected

WL.Client.connect

Im trying to find out if its better to use: WL.Device.getNetworkInfo:isNetworkConnected or WL.Client.connect

我知道getNetworkInfo仅检查手机是否与网络有竞争力,而wl.client.connect实际上将连接到服务器。我只是害怕在每次调用invokeProcedure之前,wl.client.connect都是一个昂贵的调用。是否有更好的方法在invokeProcedure调用之前检查连接?

I know that getNetworkInfo only checks if the phone has contectivity to the net, while wl.client.connect will actually connect to the server. Im just afraid that wl.client.connect will be an expensive call to make before every invokeProcedure call. Is there a better way to check for connectivity before the invokeProcedure call?

推荐答案

getNetworkInfo API可用于验证设备当前是否具有互联网连接。

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

对于WL服务器连接,只有一种方法可以验证服务器是否可访问,这是通过向WL服务器发出请求并验证其是否成功。然而,这不是正确的方法。每个WL服务器调用API,例如WL.Client.connect(),WL.Client.login(),WL.Client.invokeProcedure(),具有onSuccess和onFailure回调。使用它们来验证服务器连接是否成功。

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.

从技术上讲,即使您在提出实际请求之前执行WL.Client.connect()之类的其他请求,也不会100%保证真实请求会成功。

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.

此外,您可能希望利用每次上次WL服务器调用状态时触发的WORKLIGHT_IS_CONNECTED和WORKLIGHT_IS_DISCONNECTED事件切换成功< - >失败。在Worklight Getting Started页面查看离线培训模块。

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.

这篇关于用于检查连接的Worklight方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆