Does anyone know of a (simple)method for checking if a port is
There isn't one, short of actually attempting to bind to it. This is
because finding out whether a port is used and using that information
to determine whether or not to bind to it can lead to a race condition.
For a simple example, let's say that your code can check to see if the
port is in use. It isn't, but then a context switch occurs and
another process or thread binds to the port. The next time your code
is scheduled, it will believe the port is available even though it's
now in use -- and you'll have to handle the "port already in use"
Thus the only safe thing that can be done is to actually bind to the
port and handle the failure. You have to handle that case anyway and
you avoid the race condition.
Cocoa-dev mailing list (email@hidden)
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