NSPortNameServer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSPortNameServer.h

Overview

NSPortNameServer provides an object-oriented interface to the port registration service used by the distributed objects system. NSConnection objects use it to contact each other and to distribute objects over the network; you should rarely need to interact directly with an NSPortNameServer.

You get an NSPortNameServer object by using the systemDefaultPortNameServer class method—never allocate and initialize an instance directly. With the default server object you can register an NSPort object under a given name, making it available on the network, and also unregister it so that it can’t be looked up (although other applications that have already looked up the NSPort object can still use it until it becomes invalid). See the NSPort class specification for more information.

Tasks

Getting the Server Object

Looking Up Ports

Registering Ports

Class Methods

systemDefaultPortNameServer

Returns the single instance of NSPortNameServer for the application.

+ (NSPortNameServer *)systemDefaultPortNameServer
Return Value

The single instance of NSPortNameServer for the application.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSPortNameServer.h

Instance Methods

portForName:

Looks up and returns the port registered under the specified name on the local host.

- (NSPort *)portForName:(NSString *)portName
Parameters
portName

The name of the desired port.

Return Value

The port associated with portName on the local host. Returns nil if no such port exists.

Discussion

Invokes portForName:host: with nil as the host name.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSPortNameServer.h

portForName:host:

Looks up and returns the port registered under the specified name on a specified host.

- (NSPort *)portForName:(NSString *)portName host:(NSString *)hostName
Parameters
portName

The name of the desired port.

hostName

The name of the host. hostName is an Internet domain name (for example, “sales.anycorp.com”). If hostName is nil or empty, the local host is checked.

Return Value

The port associated with portName on the host hostName. Returns nil if no such port exists.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSPortNameServer.h

registerPort:name:

Makes a given port available on the network under a specified name.

- (BOOL)registerPort:(NSPort *)aPort name:(NSString *)portName
Parameters
aPort

The port to make available.

portName

The name for the port.

Return Value

YES if successful, NO otherwise (for example, if another NSPort object has already been registered under portName).

Discussion

A port can be registered under multiple names. If it is, it must be unregistered for each name with removePortForName: to make it completely unavailable.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSPortNameServer.h

removePortForName:

Unregisters the port for a given name on the local host.

- (BOOL)removePortForName:(NSString *)portName
Parameters
portName

The name of the port to unregister.

Return Value

YES if successful, otherwise NO.

Discussion

If the operation is successful, the port can no longer be looked up using the name portName. Other applications that already have a reference to the port can continue to use it until it becomes invalid.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSPortNameServer.h