[英]No iOS socket frameworks can connect to server socket
I'm trying to use a socket framework to connect to a socket I have. 我正在尝试使用套接字框架连接到我拥有的套接字。 I am able to connect just fine with raw socket code like:
我可以很好地连接原始套接字代码,如:
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];
but when I try with any framework I get an error and I'm completely stumped as to why. 但是当我尝试使用任何框架时,我都会收到错误,而且我完全不知道为什么会这样。 I've tried SocketRocket and Jetfire.
我试过SocketRocket和Jetfire。 Here's the code for connecting in SocketRocket that I've tried:
这是我尝试过的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];
I've also tried with the port number added. 我也尝试添加端口号。
_webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:@"wss://123.456.789.159:9900"]];
Also tried with http, https, ws. 也试过http,https,ws。 Still nothing.
依然没有。
Anybody have an idea as to why? 有谁知道为什么?
WebSocket is a protocol for bringing raw socket like functionality on top of HTTP. WebSocket是一种在HTTP之上引入类似原始套接字功能的协议。 The socket that your server is exposing likely does not support the WebSocket protocol.
服务器正在公开的套接字可能不支持WebSocket协议。
If you want a higher-level API for raw socket programming on iOS, CocoaAsyncSocket might be a good option for you. 如果你想在iOS上使用更高级别的原始套接字编程API, CocoaAsyncSocket可能是一个不错的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.