• 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
Handling Connection Timeouts with NSStream
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Handling Connection Timeouts with NSStream


  • Subject: Handling Connection Timeouts with NSStream
  • From: "Carter R. Harrison" <email@hidden>
  • Date: Fri, 10 Sep 2010 13:52:39 -0400

Hey Folks,

I'm working on a app that establishes a network connection using NSStream.  I found though that the code does not behave very well when it is trying to connect to an unreachable IP address or an IP address that just isn't accepting connections on the port I have specified.  The code I'm using is below.  Does anybody have any good ideas on how to detect a connection timeout or a complete connection failure?  Apple's documentation indicates that if a connection cannot be established the NSInputStream and NSOutputStream returned will be nil, but for some reason my checks for that never seem to work.  Any help is appreciated and thanks in advance.

NSHost *host = [NSHost hostWithAddress:address];
[NSStream getStreamsToHost:host port:port inputStream:&is outputStream:&os];

if (!is || !os)
{
	NSLog(@"This line doesn't execute, even with a bogus IP address");
}

buffer = [[NSMutableData alloc] initWithCapacity:0];
[is retain];
[os retain];

[is open];
[os open];
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Handling Connection Timeouts with NSStream
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: move drag and drop operations between different data sources
  • Next by Date: How to make template images?
  • Previous by thread: Re: SOAP requests sometimes fails
  • Next by thread: Re: Handling Connection Timeouts with NSStream
  • Index(es):
    • Date
    • Thread