<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.5.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSConnection/serviceConnectionWithName:rootObject:",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSConnection(cm)serviceConnectionWithName:rootObject:"
  },
  "title" : "serviceConnectionWithName:rootObject:"
}
-->

# serviceConnectionWithName:rootObject:

Creates and returns a new connection object representing a vended service on the default system port name server.

```
+ (instancetype) serviceConnectionWithName:(NSString *) name rootObject:(id) root;
```

## Parameters

`name`

The name of the service you want to publish.

`root`

The object to use as the root object for the published service. This is the object vended by the connection.

## Return Value

An `NSConnection` object representing the vended service or `nil` if there was a problem setting up the connection object.

## Discussion

This method creates the server-side of a connection object and registers it with the default system port name server. Clients wishing to connect to this service can request a communications port from the same port server and use that port to communicate.

## See Also

[`+ (NSPortNameServer *) systemDefaultPortNameServer;`](/documentation/Foundation/NSPortNameServer/systemDefaultPortNameServer)

Returns the single instance of `NSPortNameServer` for the application.

[`+ (instancetype) connectionWithRegisteredName:(NSString *) name host:(NSString *) hostName;`](/documentation/Foundation/NSConnection/connectionWithRegisteredName:host:)

Returns the `NSConnection` object whose send port links it to the `NSConnection` object registered with the default `NSPortNameServer` under a given name on a given host.



---

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)