Swift Lightstreamer SDK 卡在连接中

问题描述 投票:0回答:1

我当然错过了一些明显的东西,但我无法弄清楚。 我正在尝试让 Lightstreamer sdk 在 swift 中的 macOS 项目上运行。

一切都完美编译并运行,没有错误,但日志系统地指示状态:CONNECTING。

更奇怪的是,如果我指示的网址不是 Lightstreamer 服务器,则行为是相同的,日志中没有错误,只是永远“连接”。

通过 URLSession 的 HTTP 请求可以正常工作。

class TestSDK{
    let delegateTest = SubscriptionDelegateImpl()
    let loggerProvider = ConsoleLoggerProvider(level: .debug)
    
    init(){
        LightstreamerClient.setLoggerProvider(loggerProvider)
        
        let client = LightstreamerClient(serverAddress: "https://push.lightstreamer.com/", adapterSet: "DEMO")
        client.connect()
        
        let items = [ "item1", "item2", "item3" ]
        let fields = [ "stock_name", "last_price" ]
        let sub = Subscription(subscriptionMode: .MERGE, items: items, fields: fields)
        sub.dataAdapter = "QUOTE_ADAPTER"
        sub.requestedSnapshot = .yes
        sub.addDelegate(delegateTest)
        client.subscribe(sub)
    }
}

和日志:

serverAddress changed: https://push.lightstreamer.com/
adapterSet changed: DEMO
Connection requested: details: [serverAddress: https://push.lightstreamer.com/, adapterSet: DEMO, libVersion: swift_client 6.1.1] options: [requestedMaxBandwidth: unlimited, retryDelay: 4000, firstRetryMaxDelay: 100, sessionRecoveryTimeout: 15000, stalledTimeout: 2000, reconnectTimeout: 3000, idleTimeout: 19000, contentLength: 50000000]
Status: CONNECTING
WS connecting: https://push.lightstreamer.com/lightstreamer Sec-WebSocket-Protocol: TLCP-2.5.0.lightstreamer.com
subscriptionDidAddDelegate called
Subscription requested: subId: 1 [mode: MERGE, items: ["item1", "item2", "item3"], fields: ["stock_name", "last_price"], dataAdapter: QUOTE_ADAPTER, requestedSnapshot: yes]
swift macos lightstreamer
1个回答
0
投票

谢谢你找到了解决方案。 正如我怀疑的那样,这是一个新手错误,来自不同的语言,我没想到垃圾收集器这么快......

class TestSDK{
let delegateTest = SubscriptionDelegateImpl()
let loggerProvider = ConsoleLoggerProvider(level: .debug)
var client:LightstreamerClient // solution here, strong reference 

init(){
    LightstreamerClient.setLoggerProvider(loggerProvider)
    
    client = LightstreamerClient(serverAddress: "https://push.lightstreamer.com/", adapterSet: "DEMO")
    client.connect()
    
    let items = [ "item1", "item2", "item3" ]
    let fields = [ "stock_name", "last_price" ]
    let sub = Subscription(subscriptionMode: .MERGE, items: items, fields: fields)
    sub.dataAdapter = "QUOTE_ADAPTER"
    sub.requestedSnapshot = .yes
    sub.addDelegate(delegateTest)
    client.subscribe(sub)
}

}

© www.soinside.com 2019 - 2024. All rights reserved.