支持 Android 上的 Websocket [英] Support for Websockets on Android
问题描述
我即将为一个拥有大量需要实时处理的数据的客户启动一个项目.
I'm about to start a project for a client that has lots of data that needs to be real-time.
我将使用 trigger.io 和 Web UI 构建两个移动应用程序,所有这些都需要保持同步.
There are two mobile apps that I will be building with trigger.io, as well as a web UI, and all of these need to stay in sync.
我计划将 socket.io 的 WebSocket 实现与我的 Node.js 后端一起用于 web 应用程序 &移动应用程序.这将在 iOS 和现代网络浏览器上运行良好.
I plan to use socket.io's WebSocket implementation with my Node.js backend for the webapp & mobile apps. This will work great on iOS and modern web browsers.
然而,Android 的 webview 根本不支持 websockets.如果 socket.io 在 Android 上使用其长轮询回退,它只会破坏移动应用用户的数据计划.
However, Android's webview does not support websockets at all. And it would simply destroy the mobile app user's data plan if socket.io used its long-polling fallback on Android.
我想知道:是否有可能为 trigger.io Android 实现 Java WebSockets,然后将其暴露给 WebView?phonegap 有一个简单实现
I was wondering: is there any possibility of an implementation of Java WebSockets for trigger.io Android, then exposing that to the WebView? There is a simple implementation for phonegap
我想我可以为它编写一个 trigger.io 插件 - 但我想在我加入这个项目之前确定这是否可行/编写插件不太难.
I suppose I could write a trigger.io plugin for it - but I want to be sure before I jump in to this project if this is feasible / not too hard to write a plugin for.
我很久以前就使用过 trigger.io,但不是因为所有的幻想都像原生插件一样出现.
I used trigger.io long ago, but not since all the fanciness came out like native plugins.
推荐答案
如果使用 HTTP 回退解决方案不是一种选择(我会做一些计算来确定流式或长轮询解决方案是否真的会破坏移动用户的数据计划"),那么添加 WebSocket 支持的最佳解决方案可能是 trigger.io 插件.
If using an HTTP fallback solution isn't an option (I'd do some calculations to determine if a streaming or long-polling solution would really "destroy the mobile users's data plan") then the best solution to add WebSocket support would probably be a trigger.io plugin.
在 Pusher,我们在 PhoneGap 中使用了 Java 包装器,以便让我们的 JavaScript 库正常工作.但是我们已经添加了 HTTP 回退,所以我现在不建议任何人使用它.该项目在这里:https://github.com/pusher/pusher-phonegap-android
At Pusher we used a Java wrapper in PhoneGap in order to get our JavaScript library to work. However we've since added HTTP fallback so I wouldn't recommend anybody use this now. The project is here: https://github.com/pusher/pusher-phonegap-android
此处 Java 包装器的问题(我们使用 websocket-android-phonegap)是它不支持 SSL 连接(如果我没记错的话)并且它已经很长时间没有更新了.
The problem with the Java wrapper here (we use websocket-android-phonegap) is that it doesn't support SSL connections (if I remember correctly) and it hasn't been updated for a long time.
在我们创建 Pusher Java 库(支持 Android)时考虑到这一点我们在 Java-WebSocket 中使用了 WebSocket 客户端,因为它正在积极开发并支持 SSL 连接.我会推荐它.
With that in mind when we created the Pusher Java library (which supports Android) we used the WebSocket client in Java-WebSocket because it's being actively developed and supports SSL connections. I'd recommend it.
我很想知道 https://github.com/mkuklis/phonegap 的支持-websocket 提供.
这篇关于支持 Android 上的 Websocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!