Platforms to show: All Mac Windows Linux Cross-Platform
NSNetServiceMBS class
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
class | Cocoa Networking | MBS MacFrameworks Plugin | 21.1 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
The NSNetServiceMBS class represents a network service, either one your application publishes or is a client of. This class and the NSNetServiceBrowserMBS class use multicast DNS to convey information about network services to and from your application. The API of NSNetServiceMBS provides a convenient way to publish the services offered by your application and to resolve the socket address for a service.
The types of services you access using NSNetServiceMBS are the same types that you access directly using BSD sockets. HTTP and FTP are two services commonly provided by systems. (For a list of common services and the ports used by those services, see the file /etc/services.) Applications can also define their own custom services to provide specific data to clients.
You can use the NSNetServiceMBS class as either a publisher of a service or a client of a service. If your application publishes a service, your code must acquire a port and prepare a socket to communicate with clients. Once your socket is ready, you use the NSNetServiceMBS class to notify clients that your service is ready. If your application is the client of a network service, you can either create an NSNetServiceMBS object directly (if you know the exact host and port information) or use an NSNetServiceBrowserMBS object to browse for services.
To publish a service, initialize your NSNetServiceMBS object with the service name, domain, type, and port information. All of this information must be valid for the socket created by your application. Once initialized, call the publish method to broadcast your service information to the network.
When connecting to a service, use the NSNetServiceBrowserMBS class to locate the service on the network and obtain the corresponding NSNetServiceMBS object. Once you have the object, call the resolve method to verify that the service is available and ready for your application. If it is, the addresses property provides the socket information you can use to connect to the service.
The methods of NSNetServiceMBS operate asynchronously so your application is not impacted by the speed of the network. All information about a service is returned to your application through events. You must subclass and fill event handlers to respond to messages and to handle errors appropriately.
- 9 events
- event DidAcceptConnection(InputStream as NSInputStreamMBS, outputStream as NSOutputStreamMBS)
- event DidNotPublish(Error as Dictionary)
- event DidNotResolve(Error as Dictionary)
- event DidPublish
- event DidResolveAddress
- event DidStop
- event DidUpdateTXTRecordData(data as MemoryBlock)
- event WillPublish
- event WillResolve
- 12 properties
- property Address as String
- property AddressIPv4 as String
- property AddressIPv6 as String
- property description as String
- property domain as String
- property Handle as Integer
- property hostName as String
- property includesPeerToPeer as Boolean
- property name as String
- property port as Integer
- property TXTRecordData as MemoryBlock
- property type as String
- 18 methods
- method addresses as String()
- method addressesIPv4 as String()
- method addressesIPv6 as String()
- method addressesRaw as MemoryBlock()
- method Constructor(Domain as String, Type as String, Name as String)
- method Constructor(Domain as String, Type as String, Name as String, Port as Integer)
- method Constructor(other as NSNetServiceMBS)
- method Destructor
- method getStreams(byref inputStream as NSInputStreamMBS, byref outputStream as NSOutputStreamMBS) as Boolean
- method isEqual(other as NSNetServiceMBS) as Boolean
- method publish
- method publish(options as Integer)
- method resolve
- method resolve(timeout as Double)
- method setTXTRecordData(Data as MemoryBlock) as Boolean
- method startMonitoring
- method stop
- method stopMonitoring
- 4 shared methods
- shared method dataFromTXTRecordDictionary(data as Dictionary) as Memoryblock
- shared method dictionaryFromTXTRecordData(data as Memoryblock) as Dictionary
- shared method NSNetServicesErrorCode as String
- shared method NSNetServicesErrorDomain as String
- 11 constants
NetService Options
Constant | Value | Description |
---|---|---|
NSNetServiceListenForConnections | 2 | Specifies that a TCP listener should be started for both IPv4 and IPv6 on the port specified by this service. If the listening port can't be opened, the service calls its didNotPublish event to report the error. more |
NSNetServiceNoAutoRename | 1 |
Specifies that the network service should not rename itself in the event of a name collision. |
Errors
Constant | Value | Description |
---|---|---|
NSNetServicesActivityInProgress | -72003 |
The net service cannot process the request at this time. No additional information about the network state is known. |
NSNetServicesBadArgumentError | -72004 |
An invalid argument was used when creating the NSNetService object. |
NSNetServicesCancelledError | -72005 |
The client canceled the action. |
NSNetServicesCollisionError | -72001 |
The service could not be published because the name is already in use. The name could be in use locally or on another system. |
NSNetServicesInvalidError | -72006 |
The net service was improperly configured. |
NSNetServicesMissingRequiredConfigurationError | -72008 |
Missing required configuration error. |
NSNetServicesNotFoundError | -72002 |
The service could not be found on the network. |
NSNetServicesTimeoutError | -72007 |
The net service has timed out. |
NSNetServicesUnknownError | -72000 |
An unknown error occurred. |
This class has no sub classes.
Some events using this class:
- NSNetServiceBrowserMBS.DidFindService(service as NSNetServiceMBS, moreComing as Boolean)
- NSNetServiceBrowserMBS.DidRemoveService(service as NSNetServiceMBS, moreComing as Boolean)
Some examples using this class:
- /MacFrameworks/NSNetService/Bonjour Browser Console
- /MacFrameworks/NSNetService/Bonjour Browser Desktop
- /MacFrameworks/NSNetService/Bonjour Browser Web
- /MacFrameworks/NSNetService/Bonjour iOS
- /MacFrameworks/NSNetService/NSNetService iOS/Desktop App
- /MacFrameworks/NSNetService/NSNetService iOS/iOS Companion App
Blog Entries
- Using Bonjour to find iOS companion app
- MBS Xojo Plugins, version 22.3pr6
- MBS Xojo Plugins, version 22.3pr5
- News from the MBS Xojo Plugins Version 21.1
- Video about MBS Xojo Plugins 21.1
- MonkeyBread Software Releases the MBS Xojo Plugins in version 21.1
- MBS Xojo Plugins, version 21.1pr5
- NSNetService classes for Xojo
Xojo Developer Magazine
Videos
Release notes
- Version 22.3
- Fixed NSNetServiceMBS constructor to accept empty text.
- Version 21.1
- Added NSNetServiceMBS and NSNetServiceBrowserMBS classes for macOS and iOS.
The items on this page are in the following plugins: MBS MacFrameworks Plugin.
NSNetServiceBrowserMBS - NSNotificationCenterMBS