---
title: "CFNetServiceCreate(_:_:_:_:_:)"
framework: cfnetwork
role: symbol
role_heading: Function
path: "cfnetwork/cfnetservicecreate(_:_:_:_:_:)"
---

# CFNetServiceCreate(_:_:_:_:_:)

Creates an instance of a Network Service object.

## Declaration

```swift
func CFNetServiceCreate(_ alloc: CFAllocator?, _ domain: CFString, _ serviceType: CFString, _ name: CFString, _ port: Int32) -> Unmanaged<CFNetService>
```

## Parameters

- `alloc`: The allocator to use to allocate memory for the new object. Pass NULL or doc://com.apple.documentation/documentation/CoreFoundation/kCFAllocatorDefault to use the current default allocator.
- `domain`: The domain in which the CFNetService is to be registered; cannot be NULL. Call doc://com.apple.cfnetwork/documentation/CFNetwork/CFNetServiceBrowserCreate(_:_:_:) and doc://com.apple.cfnetwork/documentation/CFNetwork/CFNetServiceBrowserSearchForDomains(_:_:_:) to get the registration domain.
- `name`: A unique name if the instance will be used to register a service. The name will become part of the instance name in the DNS records that will be created when the service is registered. If the instance will be used to resolve a service, the name should be the name of the machine or service that will be resolved.
- `port`: Local IP port, in host byte order, on which this service accepts connections. Pass zero to get placeholder service. With a placeholder service, the service will not be discovered by browsing, but a name conflict will occur if another client tries to register the same name. Most applications do not need to use placeholder service.

## Return Value

Return Value A new net service object, or NULL if the instance could not be created. Ownership follows the The Create Rule.

## Discussion

Discussion If the service depends on information in DNS TXT records, call CFNetServiceSetProtocolSpecificInformation. If the CFNetService is to run in asynchronous mode, call CFNetServiceSetClient(_:_:_:) to prepare the service for running in asynchronous mode. Then call CFNetServiceScheduleWithRunLoop(_:_:_:) to schedule the service on a run loop. Then call CFNetServiceRegister to make the service available. If the CFNetService is to run in synchronous mode, call CFNetServiceRegister. To terminate a service that is running in asynchronous mode, call CFNetServiceCancel(_:) and CFNetServiceUnscheduleFromRunLoop(_:_:_:). To terminate a service that is running in synchronous mode, call CFNetServiceCancel(_:). Special Considerations This function is thread safe.

## See Also

### Network Services

- [CFNetService](cfnetwork/cfnetservice.md)
- [CFNetServiceBrowser](cfnetwork/cfnetservicebrowser.md)
- [CFNetServiceBrowserFlags](cfnetwork/cfnetservicebrowserflags.md)
- [CFNetServiceMonitor](cfnetwork/cfnetservicemonitor.md)
- [CFNetServiceMonitorType](cfnetwork/cfnetservicemonitortype.md)
- [CFNetServiceClientContext](cfnetwork/cfnetserviceclientcontext.md)
- [CFNetServiceRegisterFlags](cfnetwork/cfnetserviceregisterflags.md)
- [CFNetServicesError](cfnetwork/cfnetserviceserror.md)
- [CFNetServiceBrowserInvalidate(_:)](cfnetwork/cfnetservicebrowserinvalidate(_:).md)
- [CFNetServiceBrowserScheduleWithRunLoop(_:_:_:)](cfnetwork/cfnetservicebrowserschedulewithrunloop(_:_:_:).md)
- [CFNetServiceBrowserCreate(_:_:_:)](cfnetwork/cfnetservicebrowsercreate(_:_:_:).md)
- [CFNetServiceBrowserGetTypeID()](cfnetwork/cfnetservicebrowsergettypeid().md)
- [CFNetServiceBrowserSearchForDomains(_:_:_:)](cfnetwork/cfnetservicebrowsersearchfordomains(_:_:_:).md)
- [CFNetServiceBrowserSearchForServices(_:_:_:_:)](cfnetwork/cfnetservicebrowsersearchforservices(_:_:_:_:).md)
- [CFNetServiceBrowserStopSearch(_:_:)](cfnetwork/cfnetservicebrowserstopsearch(_:_:).md)
