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
Function: A network service that broadcasts its availability using multicast DNS.
Notes:
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.

Feedback, Comments & Corrections

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.
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.
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:

Blog Entries


The items on this page are in the following plugins: MBS MacFrameworks Plugin.


NSNetServiceBrowserMBS   -   NSNotificationCenterMBS

The biggest plugin in space...




Links
MBS Xojo Chart Plugins

Start Chat