Android Wi-Fi Direct 连接前发送数据
Android Wi-Fi Direct send data before connection
我正在开发一个使用 Wi-Fi 直接连接设备的应用程序。我在这里阅读了如何连接、发送数据和断开设备: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,它使用服务发现。
有没有一种方法可以在不使用服务发现的情况下在配对过程之前发送数据?如果我不能,你能解释一下服务发现和普通 Wi-Fi P2P 有什么区别吗?
谢谢。
除非您有其他可以依赖的媒介(例如可以用来交换信息的某种后端),否则您将需要 Service Discovery
.
关于WifiP2p
和Service Discovery
我已经写了几个答案,建议你先看看。最后一个应该是你最感兴趣的。
- Why is discovering peers for Android WifiDirect so unreliable
- Wifi P2P service discovery works intermittently
为了回答您关于 WifiP2p
和 ServiceDiscovery
之间的区别的问题,让我打个小比方:
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.
现在让我解释一下...每个人拿着一张纸代表一个Broadcasted Service
。每个broadcasted service
可以携带一小段信息(人名)。资料的space非常有限(纸上写不了多少),"relatively permanent"(改起来有点费劲)。当您在寻找合适的人时,您正在执行 Service Discovery
。你不必与所有这些人交谈来阅读这些文件上的名字——你不必连接到他们(WiFiP2p 方式)。当你找到你感兴趣的人时,你就和那个人交谈——你们建立了一个 WiFiP2p 连接。现在您可以随心所欲地与他交谈 - 您可以通过连接传递任意多的数据。
我正在开发一个使用 Wi-Fi 直接连接设备的应用程序。我在这里阅读了如何连接、发送数据和断开设备: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,它使用服务发现。
有没有一种方法可以在不使用服务发现的情况下在配对过程之前发送数据?如果我不能,你能解释一下服务发现和普通 Wi-Fi P2P 有什么区别吗?
谢谢。
除非您有其他可以依赖的媒介(例如可以用来交换信息的某种后端),否则您将需要 Service Discovery
.
关于WifiP2p
和Service Discovery
我已经写了几个答案,建议你先看看。最后一个应该是你最感兴趣的。
- Why is discovering peers for Android WifiDirect so unreliable
- Wifi P2P service discovery works intermittently
为了回答您关于 WifiP2p
和 ServiceDiscovery
之间的区别的问题,让我打个小比方:
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.
现在让我解释一下...每个人拿着一张纸代表一个Broadcasted Service
。每个broadcasted service
可以携带一小段信息(人名)。资料的space非常有限(纸上写不了多少),"relatively permanent"(改起来有点费劲)。当您在寻找合适的人时,您正在执行 Service Discovery
。你不必与所有这些人交谈来阅读这些文件上的名字——你不必连接到他们(WiFiP2p 方式)。当你找到你感兴趣的人时,你就和那个人交谈——你们建立了一个 WiFiP2p 连接。现在您可以随心所欲地与他交谈 - 您可以通过连接传递任意多的数据。