可可中的客户端到客户端消息传递?
嗯,现在我尝试在两个客户端之间而不是客户端到服务器之间进行消息传递。因此,如果我没记错的话,我们无法单独启动服务,但如何查看是单独设置还是两者都连接到同一服务?
我的启动服务的代码:
-(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的最新评论,我推荐这篇文章(来源链接在开头附近):
教程: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.