A representation of an individual host on the network.


@interface NSHost : NSObject


The NSHost class provides methods to access the network name and address information for a host. Instances of the NSHost class represent individual hosts on a network. Use NSHost objects to get the current host’s names and addresses and to look up other hosts by name or by address.

To create an NSHost object, use the currentHost, hostWithAddress:, or hostWithName: class methods (don’t use alloc and init). These methods use available network administration services to discover all names and addresses for the host requested. They don’t attempt to contact the host itself, however. This approach avoids untimely delays due to a host being unavailable, but it may result in incomplete information about the host.

An NSHost object contains all of the network addresses and names discovered for a given host by the network administration services. Each NSHost object may contain several addresses and have more than one name. If an NSHost object has more than one name, the additional names are variations on the same name, typically the basic host name plus the fully qualified domain name. For example, with a host name "sales" in the domain "", an NSHost object can hold both the names "sales" and "".

NSHost methods are thread-safe.


Creating Hosts

+ currentHost

Returns an NSHost object representing the host the process is running on.

+ hostWithAddress:

Returns the NSHost with the Internet address address.

+ hostWithName:

Returns a host with a specific name.

Getting Host Information


Returns one of the network addresses of the receiver.


Returns all the network addresses of the receiver.


Returns one of the hostnames of the receiver.


Returns the name used as by default when publishing NSNetServices.


Returns all the hostnames of the receiver.

Comparing Hosts

- isEqualToHost:

Indicates whether the receiver represents the same host as another NSHost object.

Managing the Host Cache

+ isHostCacheEnabled

Indicates whether caching is turned on or off.

+ setHostCacheEnabled:

Specifies whether the receiver is to cache instances as it creates them to avoid creating duplicate instances.

+ flushHostCache

Releases the cache of existing NSHost objects so subsequent requests for NSHost objects create new ones.



Inherits From

See Also



An abstract class that represents a communication channel.


A port that represents a BSD socket.