<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSSocketPortNameServer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSocketPortNameServer"
  },
  "title" : "NSSocketPortNameServer"
}
-->

# NSSocketPortNameServer

A port name server that takes and returns socket ports.

```
@interface NSSocketPortNameServer : NSPortNameServer
```

## Overview

Port removal functionality is supported by the [`removePortForName:`](/documentation/Foundation/NSSocketPortNameServer/removePortForName:) method and should be used to remove invalid socket ports.

Unlike the other port name servers, [`NSSocketPortNameServer`](/documentation/Foundation/NSSocketPortNameServer) can operate over a network. By registering your socket ports, you make them available to other computers on the local network without hard-coding the TCP port numbers. Clients just need to know the name of the port.

[`NSPortNameServer`](/documentation/Foundation/NSPortNameServer) is implemented using [`NetService`](/documentation/Foundation/NetService) and registers ports in the local network domain. The registered name of a port must be unique within the local domain, not just the local host. The name server only supports TCP/IP (either IPv4 or IPv6) sockets.

> Note:
> Prior to OS X 10.2, ``doc://com.apple.foundation/documentation/Foundation/NSSocketPortNameServer`` was inoperable.

## Topics

### Getting the Server Object

[`+  sharedInstance`](/documentation/Foundation/NSSocketPortNameServer/sharedInstance)

Returns the shared socket port name server.

### Looking up Ports

[`-  portForName:`](/documentation/Foundation/NSSocketPortNameServer/portForName:)

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

[`-  portForName:host:`](/documentation/Foundation/NSSocketPortNameServer/portForName:host:)

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

[`-  portForName:host:nameServerPortNumber:`](/documentation/Foundation/NSSocketPortNameServer/portForName:host:nameServerPortNumber:)

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

### Registering and Removing Ports

[`-  registerPort:name:`](/documentation/Foundation/NSSocketPortNameServer/registerPort:name:)

Registers a given port as a network service with the specified name in the local domain.

[`-  registerPort:name:nameServerPortNumber:`](/documentation/Foundation/NSSocketPortNameServer/registerPort:name:nameServerPortNumber:)

Registers a given port as a network service with the specified name in the local domain.

[`-  removePortForName:`](/documentation/Foundation/NSSocketPortNameServer/removePortForName:)

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

### Configuring the Default Port Number

[`defaultNameServerPortNumber`](/documentation/Foundation/NSSocketPortNameServer/defaultNameServerPortNumber)

Returns the port number used to contact the name server.

## Relationships

### Inherits From

[`NSPortNameServer`](/documentation/Foundation/NSPortNameServer)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)