可可中的客户端到客户端消息传递? [英] Client-to-client messaging in cocoa?

查看:143
本文介绍了可可中的客户端到客户端消息传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

erm,现在我试图做一个消息在客户端之间而不是客户端到服务器。所以如果我没有错,我们不能单独启动服务,但如何查看是单独设置还是两个连接到相同的服务?

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?

我的代码启动服务:

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


}

有任何建议吗?

推荐答案

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

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

教程: iPhone上的网络和Bonjour

我相信大多数(如果不是全部)的文章也适用于Mac平台以及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.

这篇关于可可中的客户端到客户端消息传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆