我是iOS的初学者和目标C
我使用以下代码连接服务器... 当我使用ip 192.168.10.246在本地连接时,代码工作正常并且它已连接但是当我尝试使用公共IP而不是视图只是冻结并且没有连接到服务器....
我正在使用Ray wenderlich提供的here教程
我的代码是:
NSString *pinno = @"test1234";
NSString *ip = @"publicip";
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)ip, 1234, &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
NSData *data = [[NSData alloc] initWithData:[pinno dataUsingEncoding:NSASCIIStringEncoding]];
[outputStream write:[data bytes] maxLength:[data length]];
[outputStream close];
}
答案 0 :(得分:0)
不是100%肯定,但我几乎是积极的CFStream无法连接到互联网。你需要一个NSStream。