且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将iOS和Android客户端连接到SockJS后端

更新时间:2022-03-22 20:39:42

也许这个问题已经过了一年多了。但是,因为它在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.