GCDAsyncUdpSocket and multicast sending and receiving

后端 未结 1 869
礼貌的吻别
礼貌的吻别 2020-12-30 09:53

In first approach I create client-server app ,based on sampleProject , which send some data to server.

Legend:
sender
    address = reciver ip
    port = re         


        
相关标签:
1条回答
  • 2020-12-30 10:28
    1. Multicast addresses are special reserved addresses for multicasting purpose. When a host send a data to a multicast address (group), all hosts that have joined that group will receive the data.

    2. Any host that wishes to receive data from a multicast group needs to join that group. The three steps for GCDAsyncUdpSocket are: (note that group address and group port combination must be unique for that selected multicast group)

      [_udpSocket bindToPort:_port error:&error];
      [_udpSocket joinMulticastGroup:_address error:&error];
      [_udpSocket beginReceiving:&error])
      
    3. For a sender, you don't need these two lines as you have.

      [_udpSocket bindToPort:0 error:&error];  //bindToPort:0 is same as auto-select sender port by default.
      [_udpSocket beginReceiving:&error];   //if you don't want to received, no need for this.
      

    Use the 239.0.0.0-239.255.255.255 for your private local network. Avoid 224... You can read more from the link above.

    0 讨论(0)
提交回复
热议问题