On Android, I do this to create a broadcast service using a simple linked map as information
HashMap<String, String> record = new HashMap<>(); record.put("info, "my android info"); WifiP2pDnsSdServiceInfo serviceInfo = WifiP2pDnsSdServiceInfo .newInstance("_myservice", "_tcp", record); WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); Channel channel = manager.initialize(this, this.getMainLooper(), null); manager.addLocalService(channel, serviceInfo, null);
to get another signal
manager.setDnsSdResponseListeners(channel, this, this); @Override public void onDnsSdTxtRecordAvailable(String fullDomainName, Map<String, String> txtRecordMap, WifiP2pDevice srcDevice)
On iOS, this is the same service name and information map
MCPeerID* _myPeerId=[[MCPeerID alloc] initWithDisplayName:@"my ios peer"]; NSDictionary* _serviceInfo=@ {@"info": @"my ios info"}; MCNearbyServiceAdvertiser* _serviceAdvertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:_myPeerId discoveryInfo:_serviceInfo serviceType:@"myservice"]; _serviceAdvertiser.delegate=advertiseDelegate; MCNearbyServiceBrowser* _serviceBrowser=[[MCNearbyServiceBrowser alloc] initWithPeer:_myPeerId serviceType:@"myservice"]; _serviceBrowser.delegate=browserDelegate; [_serviceAdvertiser startAdvertisingPeer]; [_serviceBrowser startBrowsingForPeers];
and delegates
-(void)browser:(MCNearbyServiceBrowser *)browser lostPeer:(MCPeerID *)peerID -(void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary<NSString *,NSString *> *)info
An Android device can only see another Android device, as well as iOS devices. However, two families cannot see each other. I would like them to see other devices, regardless of the operating system.
android ios bonjour dns-sd multipeer-connectivity
user3290180
source share