我已经在我的项目中尝试了 Socketio 库,但无法建立连接,我还想发送mattermost服务器的身份验证标头来检查连接是否成功。 任何人都可以建议任何解决方案来解决这个问题?请参阅我使用的以下代码和错误日志。
let manager = SocketManager(socketURL: URL(string: "******")!,config: [.log(true), .compress, .connectParams([JSON DATA])
}
let namespaceSocket = self.manager.socket(forNamespace: "/****")
self.addHandlers(socket: namespaceSocket)
namespaceSocket.connect()
namespaceSocket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
namespaceSocket.on(clientEvent: .error) {data, ack in
print("socket not connected")
}
/ ***** ******* ERROR /
**** LOG SocketIOClient{****}: Adding handler for event: connect
**** LOG SocketIOClient{****}: Adding handler for event: error
**** LOG SocketIOClient{****}: Handling event: statusChange with data: [connecting]
**** LOG SocketIOClient{****}: Joining namespace /****
**** LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
**** LOG SocketManager: Adding engine
**** LOG SocketEngine: Starting engine. Server: ****
**** LOG SocketEngine: Handshaking
**** LOG SocketEnginePolling: Doing polling GET ****
**** LOG SocketIOClient{/***}: Handling event: error with data: ["Tried emitting when not connected"]
答案 0 :(得分:2)
试试这个https://github.com/swiftsocket/SwiftSocket。我在我的项目中使用它并且工作得很好。使用任何合适的依赖管理器在项目中安装SwiftSocket。
Sql-Query