如何将路径(命名空间)和参数传递给CFStreamCreatePairWithSocketToHost

时间:2019-02-20 07:37:42

标签: ios websocket

我正在尝试使用 CFStreamCreatePairWithSocketToHost 方法

连接到Web套接字服务器

设置我的服务器时没有任何路径或参数,我会得到 NSStreamEventOpenCompleted

CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef) @"demo.example.com, 345, &readStream, &writeStream);

outputStream = (__bridge NSOutputStream *)writeStream;
inputStream = (__bridge NSInputStream *)readStream;

[outputStream setDelegate:self];
[inputStream setDelegate:self];

[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

[outputStream open];
[inputStream open];

- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
// streamEvent == NSStreamEventOpenCompleted
...
}

当我使用路径和参数设置服务器时,问题开始了。 例如,我需要连接到: https://demo.example.com:345/some/path?key=val&key2=val2

我尝试将路径和参数传递给主机,如下所示:

CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef) @"demo.example.com/some/path?key=val&key2=val2", 345, &readStream, &writeStream);

未成功,导致出现 kCFHostErrorHostNotFound 响应

如何将路径(命名空间)和参数正确传递给CFStreamCreatePairWithSocketToHost?

0 个答案:

没有答案