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

  • Home
  • SEARCH
  • 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 8391407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:15:10+00:00 2026-06-09T19:15:10+00:00

Bear with me please, I’m a new programmer. (things I say might not make

  • 0

Bear with me please, I’m a new programmer. (things I say might not make sense)

I’m trying to create an inputStream and outPut stream so that I can write to it using JSON objects elsewhere in the class…

I wanted to know if I’m doing it right. Currently, I’m opening the streams in -(id)init{}

 -(id)init{
_isNetworkAvailable = FALSE;
//kCFAllocatorDefault is the same thing as Null
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)requestURL, port, &readStream, &writeStream);

NSInputStream *inputStream = (__bridge NSInputStream *)readStream;
NSOutputStream *outputStream = (__bridge NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
//There should really be some checking going on here, but we're going to forget it for now
//Call some checking method
_isNetworkAvailable = TRUE;

return self;
 }

My question is: is this the right way to handle something like this? Should I declare NSInputStream and NSOutputStream elsewhere?

Why do I have to cast my CFStreams as NSStreams?

  • 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-06-09T19:15:12+00:00Added an answer on June 9, 2026 at 7:15 pm

    With some testing, this was the proper way of creating streams.
    CFStreams are cast to NSStreams because NSStreams are obj-c native and provide more options and flexibility with use. NSStream is actually based on CFStream (which is a wrapper on BSD sockets).

    This code should always be run asynchronously, as far as I can tell, or you’ll see some hanging during runtime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please bear with me, I'm new at C and I'm trying to program an
I'm a fairly new programmer so please bear with me on this. I am
I'm kind of new to this so please bear with me... Let's say I
I am a beginner programmer so please bear with me. I am trying to
I am new to C++ so please bear with me. I am trying to
Am new to MVC so please bear with me. What I'm trying to do
Very new to C so please bear with me! I'm trying to read 3
Please bear with me as I am new to dojo, javascript, and web programming
Please bear in mind that I'm totally new to Rails when answering this.My question
please bear with my newbie questions.. I was trying to convert PDF to PNG

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.