Client-to-client messaging in cocoa?

懵懂的女人 提交于 2019-12-07 21:09:48

问题


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:


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.



来源:https://stackoverflow.com/questions/1712508/client-to-client-messaging-in-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!