- (void)connection:(NSString*)serviceName forIpAddress:(NSString *)ipAddress
forPort:(NSString *)portNo
{
if(inputStream && outputStream)
//[self close];
NSString *urlString = [NSString stringWithFormat:@"http://%@",ipAddress];
NSURL *website = [NSURL URLWithString:urlString];
if (!website) {
NSLog(@"%@ is not a valid URL", website);
}
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)[website host], [portNo
intValue], &readStream, &writeStream);
CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket,
kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket,
kCFBooleanTrue);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
[self open];
}
在NNString,NSInputStream,NSoutputStream处获取ARC错误。 错误说.. c指针类型CFreadStreamRef到c指针类型NSinput流需要桥接转换。
答案 0 :(得分:0)
NSInputStream *inputStream = (__bridge_transfer NSInputStream *)readStream;
NSOutputStream *outputStream = (__bridge_transfer NSOutputStream *)writeStream;
请参见Setting Up Socket Streams编程指南。