Handling Connection Timeouts with NSStream
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