如何通过WiFi和蓝牙使用GCDAsyncUdpSocket组播 [英] How to use GCDAsyncUdpSocket for multicast over wifi and bluetooth
问题描述
我目前使用GCDAsyncUdpSocket超过iOS设备之间的无线网络发送的组播数据报。
I am currently using GCDAsyncUdpSocket to send multicast datagrams over wifi between iOS devices.
在code是pretty简单..
The Code is pretty simple..
客户端
self.socket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
//omitted error checking
[self.socket bindToPort:12345 error:&err];
[self.socket joinMulticastGroup:@"224.0.1.1" error:&err];
[self.socket beginReceiving:&err];
服务器
self.multicastSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSData *d = [@"hello" dataUsingEncoding:NSUTF8StringEncoding];
[self.multicastSocket sendData:d toHost:@"224.0.1.1" port:12345 withTimeout:-1 tag:11];
这工作得很好通过WiFi。我如何让它通过蓝牙的工作呢?我用Google搜索了一堆,并不能找到什么...我需要创建两个单独的插座?一种结合到WiFi接口和另一蓝牙接口?
This works well over wifi. How do I make it work over bluetooth as well? I have googled a bunch and can't find anything... Do I need to create two separate sockets? One bound to the wifi interface and another to the bluetooth interface?
编辑:还是我困惑的东西根本?这必须是可能的。的GameKit的GKSession正是这样做的,对吧?
or am I confused about something fundamental? This must be possible. GameKit's GKSession does exactly this, right?
推荐答案
您非常接近。您可以在<一个指向有用信息href=\"http://stackoverflow.com/questions/3844189/bonjour-over-bluetooth-without-gamekit/8273661\">this StackOverflow的问题或可以使用库如 HHServices 一个包装此功能。
You are very close. You can find pointers to useful information in this StackOverflow question or you can use a library such as HHServices that wraps this functionality.
老实说,我曾尝试与点点运气这条路,但我希望这点你在正确的方向。 <一href=\"http://stackoverflow.com/questions/14477813/usage-example-to-connect-two-ios-devices-over-bluetooth-client-server-$c$c\">Let我知道,如果你已经理解了它!
I honestly have tried this route with little luck, but I hope this points you in the right direction. Let me know if you've figured it out!
这篇关于如何通过WiFi和蓝牙使用GCDAsyncUdpSocket组播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!