2

erm,现在我尝试在两个客户端而不是客户端到服务器之间进行消息传递。因此,如果我没记错的话,我们不能单独启动服务,但是如何查看是单独设置还是两者都连接到同一个服务?

我的服务启动代码:

-(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];


}

有什么建议吗?

4

1 回答 1

2

根据您的最新评论,我推荐这篇文章(来源链接在开头附近):

教程:iPhone 上的网络和 Bonjour

我相信这篇文章的大部分(如果不是全部)同样适用于 Mac 平台,就像它适用于 iPhone 平台一样。

于 2009-11-12T01:22:04.033 回答