创建与PhoneGap的一个移动聊天应用程序 - 最好的策略是什么?最好的、应用程序、策略、PhoneGap

2023-09-10 14:14:38 作者:几位老友

我创建一个具有Ajax请求,每隔一段时间检查新邮件的定时器?这似乎是它会在手机上的巨大消耗。

Do I create a timer that does ajax requests every so often to check for new messages? This seems like it would be a huge drain on the phone.

什么是创建一个简单的PhoneGap的即时消息/聊天应用程序的最佳方法是什么?

What would be the best way to create a simple PhoneGap instant messaging/chat app?

时的HTTP流站得住脚的战略,为移动设备?如果连接中断?是否对3G的工作?

Is HTTP streaming a tenable strategy for mobile devices? What if the connection is interrupted? Does it work on 3G?

显然,这是一个很大的问题,但任何帮助将是非常美联社preciated。

Obviously this is a big question but any help would be much appreciated.

推荐答案

这个问题是有点高的水平在范围和很多会进入一个全面的回答。这取决于你使用的是什么,但你有没有考虑过使用的Node.js和WebSockets的?我知道有其他方法可以做到服务器端的WebSockets,但是这是一个流行的一种。

This question is a little high level in scope and a lot would go into a "total answer". It depends on what you're using but have you considered using node.js and websockets? I know there are other ways to do server side websockets but that is a popular one.

如果您不熟悉网络插座,这是一个新的HTML5技术和移动平台似乎要保持正确随着HTML5技术,所以这可能是你一个可行的解决方案,如果你还在寻找着什么。

If you're not familiar with web sockets, it's a new HTML5 technology and the mobile platforms seem to be keeping right along with HTML5 technologies so this may be a viable solution for you if you're still looking for something.

与网络插口的事情是,你没有为新的数据轮询为你所猜测你的问题。它保持了服务器和客户端之间的开放连接。这样一来,服务器只需要当你想将数据推到服务器的新数据推送到,当到达客户端,反之亦然。您可以使用少了很多数据和处理,因为你没有定期检查的数据。此外,它更多的是实时的经验,因为服务器接收到的消息后,被传播。

The thing with web sockets is that you don't poll for new data as what you have speculated in your question. It maintains an open connection between the server and the client. That way, the server only needs to push new data to the client when it arrives and vice versa when you want to push data to the server. You use a lot less data and processing since you don't periodically check for data. Also it's more of a "realtime" experience since messages are propagated after the server receives them.

做一个一般的谷歌搜索的WebSockets 聊天产各类教程可用。

Doing a general google search for websockets and chat yield all kinds of tutorials available.

希望有所帮助。