WebSockets 还是带有 phonegap 的替代方案? [英] WebSockets or an alternative with phonegap?

查看:12
本文介绍了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.

推荐答案

Android 或 iOS 下旧版本的 Cordova,这意味着如果你想使用 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.

更多信息请访问:http://remysharp.com/2010/10/04/websockets-in-phonegap-projects/

但是,我不确定(即使使用插件)当设备在网络连接(WiFi -> 3G -> WiFi)之间移动时 WebSockets 的弹性可能如何,因此使用简单的轮询 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 的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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