私は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
を取得します。しかし、それ以降は私のメッセージには反応しません。パスを削除したので、間違ったソケットに接続されているためです。
ホスト名にパスが追加されている場合、ソケットに接続する適切な方法は何ですか?