Unity3D — Send message to other mobile phones in t

2019-04-29 23:18发布

问题:

Say we have a group of 10 people, within 20m of one another. Each person has a mobile phone (iPhone / android / Windows phone).

And one person taps the screen to send a message.

And this is instantly registered by the others. Synchronisation is the key. It has to hit all target devices within a few milliseconds.

How might I go about this?

  • web sockets: I can't see this working as there is not guaranteed to be any Wi-Fi network. maybe I set up one phone as an access point, and the others connect to it?
  • Bluetooth: maybe?
  • Audio: maybe, speed of sound is probably close enough time resolution. But messy.
  • Anything else?

I'm working in Unity3D, although since it allows mobile plug-ins I could implement separately per platform.

An iphone-only solution would still be of interest.

EDIT: Please don't just say 'Use Bluetooth'

EDIT: One way to rephrase the question: is it possible to set up a bunch of mobile phones so that UDP packets can be sent between them? (Ad-Hoc networking?)

EDIT: Links: Transfer NSString between two devices via bluetooth in iOS Transfer data between iOS and Android via Bluetooth?

回答1:

for android, 'WiFi-Direct' will do this perfectly.

for iphone, 'Multipeer Connectivity' may be what you want.

i am an android developer, not very familier to iphone. and as far as iknow, Wifi-Direct use wifi, Multipeer Connectivity use Bluetooth.

and, iphone can connect to android WiFi-Direct soft ap.

hope this will help.



回答2:

with OSC you can broadcast to all devices in the same wifi network in realtime.

haven't used it in a while with unity, but this might help: https://github.com/jorgegarcia/UnityOSC



回答3:

This will require some experimenting, but if you can connect the phone as a peripheral to one device, and as the master for another device at the same time, you can build a ring network, where all data is transmitted to all phones.

Honestly though, you should just connect to a wifi network (router). Unless the purpose of your project is build a work around network architecture. I am assuming using the wifi hotspot feature won't work on an off-the-shelf iphone with out it being jail broken. On top of that, the API for doing such a thing doesn't appear in the documentation.

Good luck though, if you do come up with a way to do this, would be great to hear about it.

http://en.wikipedia.org/wiki/Token_ring



回答4:

Not sure if the "milliseconds" synchronization is feasible, but for the cross platform discovery part you can use an SDK such as http://p2pkit.io that abstracts all the complicated workflow behind discovering nearby devices.

Disclaimer: I work for Uepaa developing p2pkit for iOS and Android.



回答5:

Use UNET make a dedicated server running UNET and a chatroom for locations, based on geolocations.



回答6:

The audio solution seems like a very unique technique. I can not say I have ever heard about going about it in that way, but seems legit. The only problems are that it could lose accuracy due to microphone quality. I did some research and found a way to play sine/square wave sounds in c#(assuming your not using javascript for unity). Heres an example for playing them:

    int sampRate = 10000;
    short[] buf = new short[10000];
    double ampl = 0.25 * short.MaxValue;
    double freq = 5000;

    for (int s = 0; s < buf.Length; s++){

        buffer[s] = (short)(ampl * Math.Sin((2 * Math.PI * s * freq) / sampleRate));

    }

As for getting the sound and validating it to see if its a match, I'm stumped, thats where my knowledge ends, but I know its possible, but might take more work than its worth.

To answer your main question, the easiest method would be bluetooth.