本文介绍了WebSockets或替代与phonegap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将低延迟数据发送到服务器,然后返回phonegap?

How can I send low latency data to a server and back with phonegap?

考虑到我没有本地访问php文件,经验与Node.js或WebSockets我不知道应该使用哪些。

Considering I don't have access to php files locally, and don't have experience with node.js or WebSockets I don't know which ones I should use.

推荐答案

WebSockets本身不支持Android中的浏览器或,这意味着您需要使用PhoneGap插件,如果您想在客户端上使用它们。

WebSockets aren't natively supported by the browsers in Android or older versions of Cordova under iOS, which means you'll need to use a PhoneGap plugin if you want to use them on the client.

有更多的信息, :

然而,我不确定(即使使用插件)当设备移动时,WebSockets有多么有弹性(WiFi - > 3G - > WiFi),因此如果您的应用需要在用户四处移动时继续接收数据,则使用简单的轮询Web服务可能是更可靠的选项。

However, I'm not sure (even with the plugin) how resilient WebSockets are likely to be when the device moves between network connections (WiFi -> 3G -> WiFi), so using a simple polling web service may be a more reliable option if your app needs to continue receiving data as your users move around.

如果您需要接收服务器发起的数据,请考虑使用推送通知:iOS(APN)和Android(C2DM)都提供API来实现这一点,这比使用应用程序轮询更有效地使用电池您的服务器不断。

If you need to receive data initiated by the server, consider using push notifications instead: both iOS (APN) and Android (C2DM) provide APIs to do this which make more efficient use of the battery than having your app poll your server constantly.

这篇关于WebSockets或替代与phonegap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 15:56