【问题标题】:How to use GCDAsyncUdpSocket for multicast over wifi and bluetooth如何使用 GCDAsyncUdpSocket 通过 wifi 和蓝牙进行多播
【发布时间】:2015-02-13 07:37:20
【问题描述】:

我目前正在使用 GCDAsyncUdpSocket 在 iOS 设备之间通过 wifi 发送多播数据报。

代码很简单..

客户

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 上运行良好。我如何使它也可以通过蓝牙工作?我用谷歌搜索了一堆,找不到任何东西......我需要创建两个单独的套接字吗?一个绑定wifi接口,一个绑定蓝牙接口?

编辑:还是我对一些基本的东西感到困惑?这一定是可能的。 GameKit 的 GKSession 正是这样做的,对吧?

【问题讨论】:

    标签: ios bluetooth udp multicast gcdasyncsocket


    【解决方案1】:

    我认为您缺少启用 BT over ip 协议的 BT 堆栈访问。 此外,多播依赖网络设备(路由器)来管理这些组和注册。 BT 需要 ZeroConf 网络的概念(也可以用于 wifi),但以点对点的方式进行管理。 查看 Bonjour 或 Dnssd 以了解比 GameKit 更接近套接字级别的实现。

    【讨论】:

      【解决方案2】:

      你很亲密。您可以在 this StackOverflow question 中找到指向有用信息的指针,也可以使用包含此功能的库,例如 HHServices

      老实说,我尝试这条路线时运气不佳,但我希望这能指引您正确的方向。 Let me know if you've figured it out!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-16
        • 1970-01-01
        • 1970-01-01
        • 2020-12-27
        • 2012-11-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多