Disclaimer: I am the Nocode Xcode / iPhone SDK.
I am trying to establish a client TCP / IP connection with an existing server. When connecting, I expect to get some data about the server (version, etc.).
When my connection is completed, an event occurs NSStreamEventOpenCompleted, so I know that the connection is completed. Then the event fires NSStreamEventHasBytesAvailableand I execute the following code. The value 71 (int) is stored in len, which in my opinion is correct. However line
[data appendBytes:&buffer length:len]
crumbling (I think). There is no actual error, but I see , although I explicitly added the error: __TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__
case NSStreamEventHasBytesAvailable:
{
NSMutableData *data=[[NSMutableData alloc] init];
uint8_t *buffer[1024];
unsigned int len=0;
len=[(NSInputStream *)stream read:buffer maxLength:1024];
if(len>0){
@try{
[data appendBytes:&buffer length:len];
}
@catch(NSException *ex){
NSLog(@"Fail: %@", ex);
}
[statusLabel setText:[data stringValue]];
}else{
NSLog(@"No Buffer");
}
break ;
}
source
share