|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
- 11 constants
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.
The listener supports only TCP connections. If the service’s type does not end with _tcp, publication fails with NSNetServicesBadArgumentError.
Whenever a client connects to the listening socket, the service calls its didAcceptConnection event with a pair of NSStream objects.
Specifies that the network service should not rename itself in the event of a name collision.
The net service cannot process the request at this time. No additional information about the network state is known.
An invalid argument was used when creating the NSNetService object.
The client canceled the action.
The service could not be published because the name is already in use. The name could be in use locally or on another system.
The net service was improperly configured.
Missing required configuration error.
The service could not be found on the network.
The net service has timed out.
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
- 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
The items on this page are in the following plugins: MBS MacFrameworks Plugin.
MBS Xojo Chart Plugins