【问题标题】:Process for connecting to SignalR server连接 SignalR 服务器的过程
【发布时间】:2018-03-13 14:44:57
【问题描述】:

我正在使用AutosoftDMS/SignalR-Swift 客户端将我的 Swift/iOS 应用程序连接到 SignalR 服务器。我的问题是,如果 SignalR 服务器支持不同的“房间”,正确的连接顺序是什么?

示例 #1:

let hubConnection = HubConnection(withUrl: <some SignalR server URL>)

let chatHub = hubConnection.createHubProxy(hubName: "RoomChatHub")

hubConnection.started = {      
    // the value 2 is some room identifier      
    self.chatHub.invoke(method: "RoomConnect", withArgs: [2])
}

这个例子的问题是 invoke 没有处理程序来开始接收来自 2 号房间的 SignalR 服务器的消息。

示例 #2:

let hubConnection = HubConnection(withUrl: <some SignalR server URL>)

let chatHub = hubConnection.createHubProxy(hubName: "RoomChatHub")

chatHub.on(eventName: "RoomConnect") { (args) in
    if let message = args[0] as? String {
        print("Room Message: \(message)")
    }
}

这个例子的问题是 chatHub.on 方法没有允许我指定我只想要房间 #2 的消息的参数。

您如何以一种我可以说我想要某个特定房间的消息的方式连接到 SignalR 服务器?

【问题讨论】:

    标签: ios swift signalr


    【解决方案1】:

    我认为最好的方法是使用群组。您将为每个房间创建一个组并连接到适当的组。

    【讨论】:

    • 但这并没有解决根本问题。我必须传递组名或一些标识符以及客户端 API 的设置方式,我可以传递该组名,但没有回调/处理程序来接收该组的消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多