What broadcast / multicast method should we use?
We are creating a mobile App that will benefit from knowing the ID of another entity on the same network (presuming the two mobile phones are on the same WiFi network).
We would like the “master” App to send out an ID that the “slave” App’s ca开发者_运维问答n pick up and store. Regardless of when the “slave” logs on to the network it should identify the Master (get the ID of the Master) and use it until it gets a new one (from another network and a new master).
We require that the implementation is feasible under iOS and Android (preferably also under J2ME) and that the method most likely is available in normal network configurations (including public WiFi set-ups as long as the clients both have proper network access).
What broadcast / multicast method should we use?
Usability on public WiFi connections pretty much precludes IP-layer multicast.
If you are only interested in Apps within the same subnet, you might be able to do a broadcast. I think base-stations tend to have all connected machines on the same sub-net, whereas 3G networks tend to block all broadcasts between dongles.
If that fails, then an alternative approach is to have a hierarchy of masters, much like MSN. Basic idea is that a higher-level masters act as directories for local masters. Of course you have to make allowances for things like IP addresses changing, but as a general rule the longer-running an App, the more likely it will have built up a list of who else is nearby. Masters could also notice that some of its slaves have similar IP addresses (hazard: NAT), and get them to make speculative contact..
All this requires fairly generic TCP/UDP functionality, which even J2SE should have.
精彩评论