关闭

CFReadStream

709人阅读 评论(0) 收藏 举报
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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:61980次
    • 积分:1141
    • 等级:
    • 排名:千里之外
    • 原创:49篇
    • 转载:37篇
    • 译文:2篇
    • 评论:0条