我正在尝试连接到wss套接字,并且主机名称如下所示:“myhostname.com/ws/v2”。 这里是我开始的连接:如何使用NSStream连接到主机名有附加路径的wss套接字?
let host = "myhostname.com/ws/v2"
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, host as CFString, 443, &readStream, &writeStream)
inputStream = readStream!.takeRetainedValue()
outputStream = writeStream!.takeRetainedValue()
outputStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL, forKey: Stream.PropertyKey.socketSecurityLevelKey)
inputStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL, forKey: Stream.PropertyKey.socketSecurityLevelKey)
inputStream.schedule(in: .current, forMode: .commonModes)
outputStream.schedule(in: .current, forMode: .commonModes)
inputStream.delegate = self
outputStream.delegate = self
inputStream.open()
outputStream.open()
这失败的错误: The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 1.)
但是,如果我请从主机名的路径,所以它看起来是这样的:那么myhostname.com
在我代表我得到一个事件openCompleted
。然而,之后它没有回应我的消息,我认为这是因为我连接到错误的套接字,因为我删除了路径。
当主机名有附加路径时,连接到套接字的正确方法是什么?