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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to