可可中的客户端到客户端消息传递?

发布于 2024-08-10 06:58:09 字数 932 浏览 1 评论 0原文

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

我的启动服务的代码:

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


}

有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2024-08-17 06:58:09

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

教程:iPhone 上的网络和 Bonjour

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文