将iOS和Android客户端连接到SockJS后端 [英] Connect with iOS and Android clients to SockJS Backend

查看:947
本文介绍了将iOS和Android客户端连接到SockJS后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring WebSockets 开发WebSocket消息传递后端,它使用的是SockJS + STOMP协议。不使用普通WebSockets的原因是因为我需要利用SockJS在Spring WebSockets中提供的安全集成以及SockJS的其他整洁功能,例如房间,订阅等。我想知道这是否是一个很好的选择这样移动(iOS和Android)和Web客户端应用程序可以轻松连接到后端服务器并执行消息传递。如果是,那么我可以用于iOS和Android的库。

I'm developing WebSocket messaging backend using Spring WebSockets, which uses SockJS + STOMP protocol. The reason why not to use plain WebSockets is because I will need to leverage security integration that SockJS provides in Spring WebSockets and also other neat features from SockJS, such as rooms, subscriptions, etc. I was wondering if this is a good option to use so that mobile (iOS and Android) and Web client apps can easily connect to the backend server and perform messaging. If yes, then what libraries I can use for iOS and Android.

On SockJS GitHub页面他们还列出了可用的客户端库,但没有iOS或Android。所以,我想知道SockJS是否因此而值得使用。

On SockJS GitHub page they are also listing available client libraries, but no iOS nor Android. So, I'm wondering if SockJS is even worth to use just because of that.

我发现对于iOS客户端 Primus-Objc GitHub页面)库声称他们可以连接到本机WebSockets,Socket.IO,SockJS或者引擎。 io。这是一个真实的陈述吗?如果这是真的那么事件,该库的质量怎么样?

I found that for iOS client Primus-Objc (GitHub page) library claiming that they can connect to native WebSockets, Socket.IO, SockJS or perhaps engine.io. is that a true statement? And event if that's true, what about the quality of that library?

如果可以在后面使用SockJS,那么事件是否也可以显示iOS和Android的示例代码,以便我可以在移动设备上执行概念验证吗?

And event if it is ok to use SockJS on the back, then would it be also possible to show an example code for iOS and Android so that I can perform a proof of concept on mobile devices?

如果SockJS对我来说不是一个好选择,那么它会更好吗?而不是使用Socket.io + Node.js(使用JavaScript)构建我的消息传递应用程序。在我看来,Socket.io拥有iOS所需的所有客户端库(Socket.IO的官方库)家伙)和Android(Socket.IO家伙的官方图书馆)。

If SockJS is not a good option for me, then would it be better than to build my messaging app with Socket.io + Node.js (using JavaScript). Socket.io seems to me have all needed client libraries for iOS (official library by Socket.IO guys) and Android (official library by Socket.IO guys).

另一种选择可以是使用 Netty-Socket。 io 库并手动构建每个端点,而无需Spring Framework(我正在考虑使用)的任何帮助,但是我必须解决的是小问题,即安全问题。 实际上有人已经尝试过这样做了同一位作者在官方Netty-Socket.IO Github页面上提问题)但看起来他没有运气解决它。

Another option can be to use Netty-Socket.io library and build each endpoint manually without any help from Spring Framework (which I'm considering to use) but there is small challenge that I'll have to tackle, that is security. Somebody actually already tried to do it (the same author asking question on the official Netty-Socket.IO Github page) but looks like he didn't have a luck in solving it yet.

推荐答案

也许这个问题已经过了一年多了。但是,因为它在Googling for SockJS + Android时获得了第一个结果。所以,我发布了我的答案。

Maybe it's more than a year since the question was asked. But, because it's getting in the first results when Googling for SockJS+Android. So, I am posting my answer.

根据我最近一次项目的经验,我们可以使用STOMP客户端 - 就像这里的那个 - 从本机Android应用程序连接到Spring Websocket后端。

From my experience with a recent project I worked on, we were able to use a STOMP client - like the one here- to connect to Spring Websocket backend from native Android app.

从浏览器中,您仍然可以使用SockJS客户端来获得跨浏览器与websockets的兼容性。

And from the browser, you can still use SockJS client to gain across browsers compatibility to websockets with fallback.

需要注意的是,当仅使用STOMP客户端连接到本地websocket时,URL将类似于 ws: // mydomain / SockJSEndpoint / websocket
,当从浏览器使用SockJS客户端时,URL将类似于 http :// mydomain / SockJSEndpoint。

A note to mention that when using only STOMP client to connect to native websocket the URL will be something like ws://mydomain/SockJSEndpoint/websocket, and when using SockJS client from the browser the URL will be like http://mydomain/SockJSEndpoint.

这篇关于将iOS和Android客户端连接到SockJS后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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