Hi,

I have a little program that creates an NSSocketPort for use in
Distributed Objects, and also advertises itself over Bonjour. So,
something like this...

// This server will wait for responses on port 3121
receivePort = [[NSSocketPort alloc] initWithTCPPort:3121];
connection = [NSConnection connectionWithReceivePort:receivePort sendPort:nil];
...
// Create Bonjour Advertisement
netService = [[NSNetService alloc] initWithDomain:@"local"
     type:@"_myapp._tcp."
     name:hostName
     port:3121];

This all works OK, except when I run, quit, and run the app quickly.
The port 3121 isn't yet available again on the second run of the
program because the socket is still in the TIME_WAIT period from the
first run of the program. So, what I would like to do is be dynamic
and listen on a random port that is available, and make my Bonjour
advertisement for that port. Yet I am having difficulty figuring out
how to accomplish that.

// Create a generic receivePort
receivePort = [[NSSocketPort alloc] init];
connection = [NSConnection connectionWithReceivePort:receivePort sendPort:nil];
...
// Create Bonjour Advertisement
// How do I figure out the (unsigned int) value for the port to pass here???
netService = [[NSNetService alloc] initWithDomain:@"local"
     type:@"_myapp._tcp."
     name:hostName
     port:???];

The NSSocketPort class doesn't seem to have a way to get the port when
you just alloc & init like this. So How can you advertise over Bonjour
for a generic dynamically determined port selected at runtime?
_______________________________________________

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