Some comments on NetworkServer-Mac
On p. 236 the
Code:
if ([self netService] != nil) {
NSLog(@"Service was not started");
}
seems backwards to me. Shouldn't it be
Code:
if ([self netService] == nil) {
NSLog(@"Service was not started");
}
?
Once the [self startService]; method is called successfully, the netService is not nil.
In general there is an issue with the -postMessage method. Most of the messages never make it to the window.The window does not appear on screen until after the
-netServiceDidPublish method has returned, so the messages in -startService and -netServiceWillPublish have no where to go. It seems to make more sense to post them to the console. In order to make use of these messages, I added a toggleService method
Code:
- (IBAction)toggleService:(id)sender {
if (self.netService != nil) {
[self stopService];
[sender setTitle:@"Start Service"];
}
else
{
[self startService];
[sender setTitle:@"Stop Service"];
}
}
to the class with a push button in the Interface. With this invoked, the startService, netServiceDidPublish, and stopService methods do show. For some reason, the messages from the -netServiceWillPublish and -netServiceDidStop methods do not make it to the window even with this added method. They can be logged to the console and the messageLabel stringValue as well, but they never appear in the window. Thinking it may be occurring too quickly to see, I added breakpoints to try to catch the messages being displayed, but though they are logged they do not appear on the interface.
On p 239 in the -viewWillAppear method, the *browser variable is instantiated to search for browsable domains yet never is released anywhere. Should it be? I redid this with an instance variable. Is there a particular reason to not use the *localBrowser for both the domain search and the service search?
With the ability to start and stop services it is necessary to add
Code:
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
{
[self.services removeObject:aNetService];
[self.tableView reloadData];
}
so that the view is updated.
The two BOOL variables domainsFound and servicesFound are never used.
Bob