On 31 Mar '08, at 11:23 AM, Randall Meadows wrote:

My app places files in a known location in the hierarchy that apache is serving, and I need to send out a notification when I make a change that's visible via that hierarchy, so that remote apps can pick up the changes. The docs for NSDistributedNotificationCenter say I need to use distributed objects to communicate this fact to other computers (not just processes on my own).

Well, what they mean is that distributed notifications only work on a single computer, not across the network. You need to use _something_ else to send notifications over a network, but there's no reason it has to be DO.

I tend think NSNetService is what I want; it's what I use for the registering the service to begin with, but it's unclear to me how I can use that for momentary notifications ("this file changed", "this file is new"), as opposed to notifying about a long-lived service ("here's a web server").

You want to set a TXT record for the service. The TXT record basically stores metadata about the service, in the form of key-value pairs. Any other Bonjour browser that can see your service can read its TXT record; and more importantly, it can subscribe to get notifications of changes in your TXT record. For example, this is how iChat's Bonjour IM service sends out your status message and your available/busy/idle state.

This is all very efficient since it's carried in the same DNS records that are used for regular Bonjour service discovery. TXT updates are sent as link-local multicast UDP packets, so no TCP sockets need to be left open.

The main limitation is that a TXT record has to be *small*. It shouldn't exceed the size of an Ethernet packet, about 1500 bytes. If the data that clients of your service are subscribed to is larger than that, then you should use the TXT record for something like a modification-date timestamp, or a SHA-1 hash of the contents of the data. (For example, iChat doesn't store your buddy picture in the TXT record, just a hash of its data.)

The methods of NSNetService to use for publishing a TXT record are:
+ (NSData *)dataFromTXTRecordDictionary:(NSDictionary *)txtDictionary;
- (BOOL)setTXTRecordData:(NSData *)recordData
- (NSData *)TXTRecordData;

And the ones for subscribing to other services' TXT records are:
- (void)startMonitoring;
- (void)stopMonitoring;
+ (NSDictionary *)dictionaryFromTXTRecordData:(NSData *)txtData;

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to