Re: Getting error info when NSSocketPort initWithTCPPort fails
Re: Getting error info when NSSocketPort initWithTCPPort fails
- Subject: Re: Getting error info when NSSocketPort initWithTCPPort fails
- From: Wade Tregaskis <email@hidden>
- Date: Fri, 30 Jul 2004 22:17:55 +1000
In retrospect it's kind of funny/scary that virtually all the tutorial
examples or code snippets i found posted in discussion forums did not
test for the return value of initWithTCPPort:. In the one case where
there was a test, it was an if (thePort != nil) block with no else for
handling the nil case. Of course ultimately this is my fault for not
paying more careful attention to this (and it's possible I missed some
better examples), but to anyone else out there coding this stuff -
don't assume initWithTCPPort: won't return nil!
This is unfortunately a poor convention that afflicts many ObjC coders.
Apple's newer code examples are generally reasonably good, however, at
error checking.
If it's the problem I've suggested, that won't be of much help.
Trying different ports should resolve the issue in any case, so if
your program can handle that (i.e. it uses Rendezvous anyway, so a
known port is unnecessary) then by all means.
I notice that the simple 'init' method for the NSSocketPort class has
the following description:
Initializes the receiver as a local TCP/IP socket of type
SOCK_STREAM. The port number is selected by the system.
It sounds like this would take care of the port testing and return the
first available port found.
Yes, that is correct.
Wade Tregaskis (aim: wadetregaskis)
-- Sed quis custodiet ipsos custodes?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.