卓悦通过蓝牙WITHOUT的GameKit? [英] Bonjour over bluetooth WITHOUT Gamekit ?
问题描述
我想知道用直接通过蓝牙卓悦在iPhone OS 3.0或更高版本,而无需使用的GameKit的可能性。任何人都可以提供任何例子吗?
I am wondering the possibility of directly using bonjour over bluetooth in iPhone OS 3.0 or later without using GameKit. Can anyone provide any examples ?
推荐答案
刚刚公布的服务,就像 TC。说下面:
Just announce the service, just like tc. has said below:
self.netService = [[[NSNetService alloc] initWithDomain:@""
type:@"_http._tcp"
name:@""
port:8080] autorelease];
[self.netService publish];
使用iOS5的,但是,let's叩它的蓝牙卓悦默认情况下禁用,所以你必须使用&LT声明的C API; dns_sd.h>
。
With iOS5, however, let's-call-it "Bluetooth Bonjour" is disabled by default, so you have to use the C API declared in <dns_sd.h>
.
DNSServiceRef serviceRef;
DNSServiceRegister(&serviceRef, // sdRef
kDNSServiceFlagsIncludeP2P, // interfaceIndex
0, // flags
NULL, // name
"_http._tcp", // regtype
NULL, // domain
NULL, // host
1291, // port
0, // txtLen
NULL, // txtRecord
NULL, // callBack,
NULL // context
);
这是刚刚公布的部分;解决更复杂一点。我建议你看看苹果下面的例子:
This is just the announcement part; resolving is a bit more complex. I suggest you take a look at the following examples from Apple:
- SRVResolver - 演示了如何查找使用
&LT宣布API的服务; dns_sd.h&GT;
。目标OS X,但包括一个叫做SRVResolver
类,你可以在iOS上使用一样容易,你可以在OS X上使用它的iOS 5蓝牙P2P工作,更新来电DNSServiceQueryRecord()
通过kDNSServiceFlagsIncludeP2P
为interfaceIndex
。 (注意!此示例似乎并不在OS X 10.8 docset的存在,可在10.6和10.7 docsets找到。在10.8,还有的DNSSDObjects例子,但我没有看正是在它做什么。) - WiTap - 只要你不真正关心在iOS 5支持蓝牙,只看所谓WiTap的例子,它不但彰显美丽的Objective-C API,却怎么也可以创建一个使用CFSocket服务器的API(约BSD套接字薄包装)。你会想在这个看起来即使您正在使用SRVResolver来看看如何使用基于C-API从
&LT; dns_sd.h方式&gt;
- SRVResolver - demonstrates how you can look up a service using API declared in
<dns_sd.h>
. Targets OS X, but includes a class calledSRVResolver
which you can use on iOS as easily as you can use it on OS X. For iOS 5 Bluetooth P2P to work, update the call toDNSServiceQueryRecord()
to passkDNSServiceFlagsIncludeP2P
as theinterfaceIndex
. (NOTE! This sample does not seem to exist in OS X 10.8 docset. It can be found in 10.6 and 10.7 docsets. In 10.8, there's the DNSSDObjects example, but I didn't look exactly at what it does.) - WiTap - as long as you don't actually care about Bluetooth support on iOS 5, just look at the example called WiTap, which demonstrates not only the beautiful Objective-C API, but also how you can create a server using CFSocket APIs (thin wrappers around BSD sockets). You'll want to look at this even if you are using SRVResolver to see how to use C-based API from
<dns_sd.h>
.
宣布或解决您的服务后,可以使用常规的BSD套接字听或连接。当编写一个服务器,你甚至会想先听()
端口0(零),然后它随机可用端口分配给您查询。查询该后,宣布这一端口,而不是固定的。这正是WiTap例子做(但CFSocket API,而不是BSD套接字API)。
After announcing or resolving your service, you use regular BSD sockets to listen or connect. When writing a server, you may even want to first listen()
on port 0 (zero), and then query which random available port was assigned to you. After querying for that, announce this port instead of a fixed one. That's exactly what WiTap example is doing (but with CFSocket API instead of BSD socket API).
有关BSD套接字的详细信息,只是谷歌周围的教程。
For more info on BSD sockets, just Google around for a tutorial.
的注:关于iOS 5的信息来自苹果的<一个href=\"http://developer.apple.com/library/ios/#qa/qa1753/_index.html#//apple_ref/doc/uid/DTS40011315\">Technical Q&安培; A QA1753 的
这篇关于卓悦通过蓝牙WITHOUT的GameKit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!