• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CFHTTP functions (the CallBack funtion is never called...)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CFHTTP functions (the CallBack funtion is never called...)


  • Subject: CFHTTP functions (the CallBack funtion is never called...)
  • From: "Alex Guo" <email@hidden>
  • Date: Fri, 26 Nov 2004 17:56:54 +0800

Hi, EveryBody,
 
  I write a demo using CFHTTP functions, but seems that the CallBack function is never called (sigh...). AnyBody can help me? thanks a lot.
  The followings are the code snippet:
 
#include <Carbon/Carbon.h>
 
static const CFOptionFlags kNetworkEvents = kCFStreamEventOpenCompleted     |
                                            kCFStreamEventHasBytesAvailable |
                                            kCFStreamEventEndEncountered    |
                                            kCFStreamEventErrorOccurred;
 

void handleNetworkEvent(CFStreamEventType);
 
static void
readStreamClientCallBack(CFReadStreamRef stream, CFStreamEventType type, void *clientCallBackInfo) {
    // hanle network events
 printf("call back function is called\n");
 handleNetworkEvent(type);
}
 
CFReadStreamRef _stream;
 
CFHTTPMessageRef _request;
 
CFHTTPMessageRef _response;
 
int main(int argc, char* argv[])
{
 printf("hello, xcode\n");
 
 CFURLRef url = "" CFSTR("http://192.168.0.58"), NULL);
 if(url == NULL) {
  printf("error: create url\n");
  return -1;
 }
 
 _request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), url, kCFHTTPVersion1_1);
 CFRelease(url);
 if(_request == NULL) {
  printf("error: create request\n");
  return -1;
 }
 
 _stream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, _request);
 CFRelease(_request);
 if(_stream == NULL) {
  printf("error: create stream for request\n");
  return -1;
 }
 
// CFStreamClientContext is used for callback function to receive user-defined data.
//    CFStreamClientContext ctxt = {0, NULL, NULL, NULL, NULL};
 
 // Set client: call back function
// if(! CFReadStreamSetClient(_stream, kNetworkEvents, readStreamClientCallBack, &ctxt)) {
 if(! CFReadStreamSetClient(_stream, kNetworkEvents, readStreamClientCallBack, NULL)) {
  CFRelease(_stream);
  printf("error: set client to read stream\n");
  return -1;
    }
 
 // Schedule the stream
 CFReadStreamScheduleWithRunLoop(_stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
 
 // Start the HTTP connection
 if(! CFReadStreamOpen(_stream)) {
  CFReadStreamSetClient(_stream, 0, NULL, NULL);
  CFReadStreamUnscheduleFromRunLoop(_stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
  CFRelease(_stream);
  printf("error: open stream to send http request");
  return -1;
 }
 
 printf("exit main entry...");
 return 0;
}
 
 
Thanks,
Alex Guo
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Mail Settings
  • Next by Date: Re: CFHTTP functions (the CallBack funtion is never called...)
  • Previous by thread: Re: Mail Settings
  • Next by thread: Re: CFHTTP functions (the CallBack funtion is never called...)
  • Index(es):
    • Date
    • Thread