Re: Bonjour will not resolve in separate thread
Re: Bonjour will not resolve in separate thread
- Subject: Re: Bonjour will not resolve in separate thread
- From: Adam Leonard <email@hidden>
- Date: Sun, 9 Apr 2006 15:25:40 -0700
I don't think NSNetService is thread safe (its not mentioned here:
http://developer.apple.com/documentation/Cocoa/Conceptual/
Multithreading/articles/CocoaSafety.html)
But anyway, why do you need to run this in a separate thread? Your
code should not block the main thread because resolveWithTimeout:
runs asynchronously. Just run this in the main thread then spawn a
new thread when you are actually transferring data through the
connection.
Adam Leonard
On Apr 9, 2006, at 3:00 PM, Will Koffel wrote:
I'm trying to resolve a Bonjour service. It's happening in a
background thread.
[NSThread detachNewThreadSelector:@selector(loadData:)
toTarget:loader withObject:self];
The loader implements loadData, does nothing right now except
instantiate an autorelease pool and then try to resolve a service:
- (void)loadData:(id)caller {
NSAutoreleasePool *threadPool = [[NSAutoreleasePool alloc] init];
NSNetService *service = [[NSNetService alloc]
initWithDomain:@"local." type:@"_http._tcp."name:@"Steam"];
[service setDelegate:self];
[service resolveWithTimeout:5.0];
[threadPool release];
}
- (void)netServiceDidResolveAddress:(NSNetService *)sender {
NSLog(@"resolved %@", sender);
}
- (void)netService:(NSNetService *)sender didNotResolve:
(NSDictionary *)errorDict {
NSLog(@"failed to resolve %@", sender);
}
- (void)netServiceWillResolve:(NSNetService *)sender {
NSLog(@"will resolve %@", sender);
}
I get the notification that the service "will resolve", but I never
get a resolution or a failure. If I do the same in the main
thread, it works with no problems.
Any ideas? The only thing I've found was a vague reference to
needing an NSRunLoop, but I'm pretty sure that the new thread's
default run loop will work.
-Will
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden