I'm developing an app which uses Wi-Fi direct to connect devices. I read how to connect, send data and disconnect the devices here: http://developer.android.com/guide/topics/connectivity/wifip2p.html. Now, I'd like to send some data BEFORE the connection, in order to show some informations about the device. I've Googled this but the only answer I've found is this: Sending data in Android WiFi Direct service discovery instead of connecting, which uses services discovery.
Is there a way I can send data before the pairing process without using the service discovery? If I can't, can you explain what is the difference between service discovery and normal Wi-Fi P2P?
Thank you.
Unless you have some other medium you can rely on (e.g. some sort of back-end you can use to exchange information), you will need Service Discovery
.
I have already written a few answers regarding WifiP2p
and Service Discovery
, and I suggest you take a look at them first. The last one should probably interest you the most.
To answer your question about the difference between WifiP2p
and ServiceDiscovery
, let me use a small analogy:
Imagine you're at the airport, you've just landed in a foreign country. You're leaving the duty-free zone and you see all the people that are waiting for people who have landed at the airport just like you did. You need to find your taxi driver. You know he should be waiting for you with a small piece of paper with your name on it. You can see many guys like that, every single one of them is holding a piece of paper with a name on it. You need to read through many of them until you find the one with yours. But you don't have to talk to all those people. You will talk only to your taxi driver, and you will probably tell much more than just your name.
Now let me explain... Every single person holding a piece of paper represents a Broadcasted Service
. Every broadcasted service
can carry a small piece of information (a person name). The space for the information is very limited (you can't write much on the paper), and is "relatively permanent" (it takes a bit to change it). When you were searching for the right person, you were performing a Service Discovery
. You did not have to talk to all those people to read the names on those pieces of papers - you didn't have to connect to them (WiFiP2p-wise). When you found the one you were interested in, you talked to the man - you established a WiFiP2p connection. Now you can talk to him as much as you want - you can pass as much data as you want through the connection.