All pastes #2074532 Raw Edit

Miscellany

public text v1 · immutable
#2074532 ·published 2011-06-04 10:56 UTC
rendered paste body

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
    switch(eventCode) {
        case NSStreamEventHasBytesAvailable:
        {
            uint8_t buf[512];
            unsigned int len = 0;
            len = [(NSInputStream *)stream read:buf maxLength:511];
            if(len) {
//                [data appendBytes:(const void *)buf length:len];
                NSData *data = [NSData dataWithBytes:(const void *)buf length:len];
                // bytesRead is an instance variable of type NSNumber.
                
                //[bytesRead setIntValue:[bytesRead intValue]+len];
                NSLog(@"ASD! %@ STRING: %@", data, [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]);
                
            } else {
                
                NSLog(@"no buffer!");
                
            }
            break;
        }
    }
}