Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:31:04+00:00 2026-05-20T10:31:04+00:00

I am new to Cocoa/iOS – iphone platform I am trying to work with

  • 0

I am new to Cocoa/iOS – iphone platform

I am trying to work with network streams using Core Foundations. I am following the CFNetworking guide but I can’t get a simple test to work. The following compiles and runs but nothing is recorded to NSLog.

I am providing the Callback, clientCB, to CFReadStreamSetClient and scheduling the readStream on the run loop (at least that’s the idea).

I was expecting the CallBack to report something.

Can someone tell me where I am going wrong? I have telnet’d to this server and it works. Any suggestions would be helpful.

Thanks.

void clientCB(CFReadStreamRef stream, CFStreamEventType event, void *myPtr)
{
    switch(event) {
        case kCFStreamEventHasBytesAvailable:{
            UInt8 buf[BUFSIZE];
            CFIndex bytesRead = CFReadStreamRead(stream, buf, BUFSIZE);
            if (bytesRead > 0) {
              NSLog(@"Server has data to read!");
            }
            break;
        }
        case kCFStreamEventErrorOccurred:
            NSLog(@"A Read Stream Error Has Occurred!");
        case kCFStreamEventEndEncountered:
            NSLog(@"A Read Stream Event End!");
        default:
            break;
    }

}



- (IBAction) connectToServer: (id) sender

{
    CFReadStreamRef readStream; 
    CFWriteStreamRef writeStream;
    CFHostRef host = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)@"irc.freenode.net");
    CFStreamCreatePairWithSocketToCFHost(kCFAllocatorDefault, host, 6667, &readStream, &writeStream);

    CFStreamClientContext myContext = {
        0,
        self,
        (void *(*)(void *info))CFRetain,
        (void (*)(void *info))CFRelease,
        (CFStringRef (*)(void *info))CFCopyDescription
    };

    CFOptionFlags registeredEvents = kCFStreamEventHasBytesAvailable |
                                kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered;

    if(CFReadStreamSetClient(readStream, registeredEvents, clientCB, &myContext))
    {
        CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:31:05+00:00Added an answer on May 20, 2026 at 10:31 am

    It seems that you forgot to call CFReadStreamOpen.

        if(CFReadStreamSetClient(readStream, registeredEvents, clientCB, &myContext))
        {
            CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
        }
    
        if (!CFReadStreamOpen(readStream)) {
            /* error handling */
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using XCode to develop a Cocoa touch application for the iOS platform
Brand new to Cocoa and I'm trying to figure out how to copy an
I am very new to iOs and cocoa framework. The UIImagePickerControl allows me to
First of all, I am a a very new Objective C/Cocoa iOS Developer but
I'm new to Cocca and IOS development and find myself in the following situation.
Very new to programming for iOS and Cocoa so please take it easy on
Baby new to Xcode, Cocoa touch and iOS development in general. And am taking
I created a new cocoa project using the command-line tool template. I need to
I am trying to create a site-specific browser application. I've created a new Cocoa
New to Cocoa and Objective-c. Do I need getters and setters if I'm depending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.