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 6981107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:06:49+00:00 2026-05-27T18:06:49+00:00

I am desperately trying to figure out how to detect errors when opening TCP

  • 0

I am desperately trying to figure out how to detect errors when opening TCP streams using NSStream +getStreamsToHost/CFStreamCreatePairWithSocket(). If I do this:

NSInputStream* input = nil;
NSOutputStream* output = nil;
[NSStream getStreamstoHost:[NSHost hostWithName:@"localhost"] port:80 inputStream:&input outputStream:&output];

NSError* error1 = [input streamError];
assert(error1 == nil);
NSStreamStatus status1 = [input streamStatus];

[input open];
NSError* error2 = [input streamError];
assert(error2 == nil);
NSStreamStatus status2 = [input streamStatus];

status1 is NSStreamStatusNotOpen, which is expected. error1 is nil. error2 is also nil, and status2 is NSStreamStatusOpening. If I telnet to the same address, I get connection refused – there is nothing listening on port 80. If I try to connect to some nonsensical address, such as yaddayadda, I get nil streams.

How do I handle errors properly? No example anywhere seems to handle error conditions, and the docs don’t say anything about it, other than the streams may be nil. I’m stumped. Don’t tell me I have to run the connection through a run loop, just to get proper error handling…?

I know there’s always the possibility of using good ol’ BSD sockets, but the docs warns against that, as some high level networking features may fail (auto connections over VPN, and similar stuff).

  • 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-27T18:06:50+00:00Added an answer on May 27, 2026 at 6:06 pm

    What you need to do is either poll for the status using the streamStatus method on the input stream, or schedule the streams for events in a run loop. To better provide error information about erroneous host names, it’s better to resolve the name before hand using either NSHost or CFHost.

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

Sidebar

Related Questions

I'm new to django, and desperately trying to figure out why I can't get
I've been desperately trying for about the last week to figure out whatever my
I've been trying to figure this out for a while, and I just can't.
Right now I'm trying desperately to get @font-face to work in my website. This
I have been trying desperately to fix this issue where my ListView items are
I'm desperately trying to avoid a for loop in Matlab, but I cannot figure
I am currently trying to figure out a way on how I can possibly
I'm desperately trying to solve this one. I have a bunch of files stored
I'm trying desperately to design my UI programmatically. But I think I'm in trouble
I've been trying desperately to get my application (15 C# dlls and 1 C++/CLI

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.