Database Reference
In-Depth Information
[socket release], socket = nil;
[service stop];
[service release];
[self startTestTimers];
}
Once the NSNetService has been resolved, we can retrieve its addresses and
connect to it. With access to the address from the NSNetService , we can initialize
an NSSocketPort to connect to the server hosting the service. With the NSSocketPort
initialized, we can then initialize an NSConnection and finally get a reference to
the -rootProxy of the NSConnection , which is actually an NSDistantObject proxy for
the AppDelegate of the server.
Once we have the server referenced properly, we can shut down the Bonjour
NSNetService and start our tests.
11.3
Testing the Networking Code
Whenever I build an application that needs to communicate to a server or
another device, I always start off with simple tests to confirm that the connec-
tion is working. I generally leave these tests in place until the code goes to
production. This both provides me with a simple way to test the connectivity
and gives me a base to fall back upon if some of the higher-level functions
start to fail. For this application, let's start by setting up a group of timers
that will fire off our test methods.
-startTestTimers Implementation
To simulate a large amount of client-server traffic, this application runs sev-
eral timers at a fairly high pace. This will help us catch any race conditions
or other issues with the distributed nature of this application.
DistributedCDClient/AppDelegate.m
- ( void )startTestTimers
{
SEL selector = @selector (testPing);
pingTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:selector
userInfo:nil
repeats:YES];
selector = @selector (testObjectInsertion);
insertTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:selector
userInfo:nil
repeats:YES];
selector = @selector (testObjectDeletion);
 
 
 
Search WWH ::




Custom Search