CFReadStream

转载 2012年03月27日 09:56:55
static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventType type, void *clientCallBackInfo)
{
    NSLog(@"call Back");
    UInt8 buffer[1024*40];
    
    NSInteger bytesRead = [readStream read:buffer maxLength:sizeof(buffer)];
    NSLog(@"bytesRead:%s",buffer);

}


    NSURL* url1 = [NSURL URLWithString:@"http://www.baidu.com"];

     
    CFHTTPMessageRef message = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), (CFURLRef)url1, kCFHTTPVersion1_1);
    CFHTTPMessageSetBody(message, (CFDataRef)(CFSTR("")));
    
    CFReadStreamRef readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, message);
    CFOptionFlags events = kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered;
    
    // print "client = 1" here                    
    //NSLog(@"client = %d" , CFReadStreamSetClient(readStream, events, readStreamEventCallBack, & dataStreamContext));
    
    CFStreamClientContext dataStreamContext = {0, self, NULL, NULL, NULL};
    
    if(CFReadStreamSetClient(readStream, events, ReadStreamClientCallBack, & dataStreamContext)) {
        CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
    }
    
    
    CFReadStreamOpen(readStream);
    NSLog(@"end request");

 

 

http://www.google.com.hk/url?sa=t&rct=j&q=CFHTTPMessageCreateRequest+++google&source=web&cd=3&ved=0CEwQFjAC&url=http%3A%2F%2Fvirtual-mechanic.googlecode.com%2Ffiles%2FCFNetwork.pdf&ei=PL5xT8Vh0ZqJB8mjueQP&usg=AFQjCNF4wmXQvH97GLdRcaLN10EqFGwYXQ&cad=rjt

相关文章推荐

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CFReadStream
举报原因:
原因补充:

(最多只允许输入30个字)