views:

224

answers:

1

Hi, erm, now I trying to do a messaging between both client instead of client to server. So if I'm not wrong we can't startup service individually but how to see whether is setting up individually or both connect to same service?

My Code for startup the service:

-(void)startService {
    // Start listening socket
    NSError *error;
    self.listeningSocket = [[[AsyncSocket alloc]initWithDelegate:self] autorelease];
    if ( ![self.listeningSocket acceptOnPort:0 error:&error] ) {
        NSLog(@"Failed to create listening socket");
        return;
    }

    // Advertise service with bonjour
    NSString *serviceName = [NSString stringWithFormat:@"Aho- %@",
                                [[NSProcessInfo processInfo] hostName]];
    connectedService = [[NSNetService alloc] initWithDomain:@"" type:@"_cocoaforsci._tcp."
                                                       name:serviceName
                                                       port:1234];
    connectedService.delegate = self;
    [connectedService publish];


}

Any suggestion?

+1  A: 

Based on your latest comment, I recommend this article (source is linked near the beginning):

Tutorial: Networking and Bonjour on iPhone

I believe most (if not all) of the article applies just as well to the Mac platform as it does to the iPhone platform.

Joshua Nozzi
oh, thanks for the link!! Anyway, do you know what's the code for hard coding the peer ip address instead of searching for it? Using NSNetservice.
xTohrux
No problem. You should, however, post the IP address topic as a new question.
Joshua Nozzi