我测试了僵尸,它给出了这种类型的错误,我的应用程序崩溃很多次并显示相同的错误。
https://i.stack.imgur.com/KStvf.png
这是我的代码
- (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) {
BFLog(@"%@ is not a valid URL", website);
}
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)[website host], [portNo intValue], &readStream, &writeStream);
CFReadStreamSetProperty(readStream,kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream,kCFStreamPropertyShouldCloseNativeSocket,kCFBooleanTrue);
inputStream = (__bridge NSInputStream *)readStream;
outputStream = (__bridge NSOutputStream *)writeStream;
[self open];
}
打开套接字
- (void)open{
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
}
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
case NSStreamEventHasBytesAvailable:
event = @"NSStreamEventHasBytesAvailable";
if (theStream == inputStream)
{
uint8_t buffer[1024];
int len;
while ([inputStream hasBytesAvailable])
{
len = (int)[inputStream read:buffer maxLength:1024];
if (len > 0)
{
NSMutableString *output = [[NSMutableString alloc] initWithBytes:buffer length:len encoding:NSUTF8StringEncoding];
if (nil != output)
{
BFLog(@"Received data--------------------%@", output);
BFLog(@"marr delete data..%@",marrDelId);
[self deletedata:@""];
}
}
}
}
break;
}