我正在尝试使用套接字框架连接到我拥有的套接字。我可以使用原始套接字代码很好地连接,例如:
uint portNo = 9900;
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"123.456.789.159", portNo, &readStream, &writeStream);
inputStream = (__bridge NSInputStream *)readStream;
outputStream = (__bridge NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
但是当我尝试使用任何框架时,我都会遇到错误,我完全不知道为什么。我试过 SocketRocket 和 Jetfire。这是我尝试过的在 SocketRocket 中连接的代码:
_webSocket.delegate = nil;
[_webSocket close];
_webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:@"wss://123.456.789.159"]];
_webSocket.delegate = self;
NSLog(@"Opening Connection...");
[_webSocket open];
我也尝试过添加端口号。
_webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:@"wss://123.456.789.159:9900"]];
还尝试了 http、https、ws。依然没有。
有人知道为什么吗?