Reputation: 787
The WifiP2pDevice only provides the MAC address. http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pDevice.html
I want to get the IP address (but not MAC address) of other devices after requestPeers(). How can this be done?
Upvotes: 3
Views: 3706
Reputation: 4087
WifiP2p auto assigns the IP once the device is connected in the group. Basically the group-owner acts as a DHCP server and assigns IPs to all the other peers in the group and GO gets the GO_IP = 192.168.49.1
.
Assign a role to GO that whenever new device connects send it the hashmap of MAC Address versus IP by reading from the file /proc/net/arp
. Now when you want to send a file or message to a MAC address read its IP from this hashmap. But the peers can send the message to GO only so you need to assign the role to GO if the message is sent for an IP other than GO_IP then it forwards it to the respective device.
Let me know if you find any problems with this solution.
Upvotes: 2
Reputation: 2188
There is a way to achieve this ...
Adding Network Service Discovery (NSD)
to your app allows your users to identify other devices on the local network that support the services your app requests. This is useful for a variety of peer-to-peer applications such as file sharing or multi-player gaming.
first you need to do
1.Register Your Service on the Network
2.Discover Services on the Network
3.Connect to Services on the Network
4.Unregister Your Service on Application Close
after complete 3 no points your application receives detailed service information including an IP address
and port number
. This is everything you need to create your own network connection to the service.
Take a look for details (including sample app).. click. second link ..click
Upvotes: 2