【问题标题】:Swift StompClient Vs SockJS not consistent behavior during connectionSwift StompClient Vs SockJS 在连接期间的行为不一致
【发布时间】:2017-02-07 02:08:36
【问题描述】:

我正在使用 StompClient (https://github.com/ShengHuaWu/StompClient) 将我的 iOS (swift 3) 应用程序连接到托管在 Spring 容器中的 stomp 套接字。

似乎当从网络浏览器使用 sockjs 并连接到 ws:/server/topic_name 时,它​​会自动将 server_id 和 session_id 添加到 url (ws://server/server_id/socket_id/topic_name)。

当我使用 Swift StompClient 时,它似乎没有将这些额外的项目添加到路径中。

有人知道如何解决这个问题吗?

【问题讨论】:

  • 你成功使用盛华客户端了吗?我看到了同样的问题,但我有点想我们需要在我们的 URL 上手动调用 appendServerIdAndSessionId

标签: swift stomp


【解决方案1】:

Sockjs 是为在浏览器中使用而设计的,因为尚未在所有浏览器中支持 WebSocket。你上面提到的url是sockjs协议的一部分。

iOS 原生支持 WebSocket。所以你不需要依赖 sockjs。有像这样的 Stomp 库,您可以使用 https://github.com/mobile-web-messaging/StompKit

需要注意的一点是,如果您使用的是 Spring 容器,并且假设您在应用程序上下文中进行了配置:

    <websocket:stomp-endpoint path="/spring-websocket-portfolio/portfolio" allowed-origins="*">
        <websocket:sockjs/>
    </websocket:stomp-endpoint>

您应该连接到 ws://localhost/spring-websocket-portfolio/portfolio/websocket。

【讨论】:

    猜你喜欢
    • 2020-03-02
    • 1970-01-01
    • 2014-01-03
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多