What is different of NSD and WifiP2pManager? - android

There are several choice for making a WiFi program in android, most common methods are using NSD and WifiP2pManager.
What is different between these 2 choice?

Firstly, these are not two entities to be differentiated. Even if you use Wi-Fi P2p for NSD, you should use WifiP2pManager for connection initiation and negotiation. NSD is to be used for Discovery phase
I assume your question to be difference between Using Wi-Fi P2p Service Discovery(NSD) and Not using it (using normal scan WifiP2pManager.discoverPeers() ).
The answer is explicitly provided here under three sub-topics. However
The difference is actually in the initial phase: The peer discovery phase
When you don't use the Wi-Fi P2p Service discovery, you scan for all
devices that are active with WiFi direct. The scan result list may contain peers that are not of your interest. You can't help it, as you do not have a filter.
In the case where you need to discover only peers that are of your
interest, then Wi-Fi P2p Service discovery should be used. Here, the
filter condition is set in the name of Service.
For ex: your app "XYZ" needs
to form groups ONLY with other devices that also use the same app
"XYZ", then you can create a service and name it, say service_xyz,
and this service info will be broadcast along with the Wi-Fi Direct
device details. On the receiver end, you implement a service listener
that listens for the service "service_xyz". By doing so, only devices
with the desired service name are discovered and listed. Useful for
gaming apps, social networking apps.
However, after this phase, in both the methods, from the discovered list a particular device is selected and connect request is initiated. From here on, the following phases are the same - connection request, negotiation, group formation...
hope this helped you.

Related

WiFi Data Sharing with socket in android

I am trying to connect multiple devices via Wifi Direct and create a group owner so that the client devices can connect to group owner.
when group owner send or push a message then all connected client devices get this message at the same time.
Is this possible in Android ?
If yes, please provide me some documentation or sample code.
in essence, you would just use the normal Wifi Direct API.
In essence, you would need to advertise local service in order others devices to know which device they should connect to. And the one that advertises should be the Group owner.
in-case you could decide who's the group owner, then use the creategroup function to create a group, then add local service to advertise it, and to make the advertisement visible, you would need to keep peer discovery active, until you get first connection.
Then with Clients, just do discovery and find the device that is advertising the service and make connections to it.
Then in GO, after each connection changed event, get first connection information to see that you are really a GO, and then get group information to see how many clients you have connected to you.Note that new connection can also cause disconnected event to be shown, thus prepare your logic to handle those situations as well.
With clients, once you get connected event, then get connection information so you'll get the IP address of the GO.
GO should have active tread always accepting incoming connections, so your clients can connect it, and your GO would get the IP addresses of the clients connected to it.

android wifi direct. setting PBC message and peer list

I searched in many topics and forums. But i still don't find the way to do this.
How can we set the wifi direct request connection message.
And so.
How can we set the peer info list to see not just is android ID, but things like a pseudo, a player level or rank, etc...
Any help is welcome.
Thanks.
short answer is: You don't.
Basically the peer list shows just peer information. If you need more then you need to do Service discovery after the peer discovery. Though if you do just quick discovery, then its rather safe to do only Service discovery. For reference see my blog article
With service discovery you could deliver data wither via Bonjour or UPnP.
With UPnP limitations for data delivery are summarized in here.
And with Bonjour you could either deliver some 100 bytes of data via instance name variable in service advertisement, or have data added to Dns-Sd records. The limitations are summarized also in my blog.

How to find a Group owner device automatically

I am developing an android application , in which i need to connect multiple devices with each other using WiFi Direct. i am done with multiple connections as i am aware of connecting devices through one group owner device as if all client devices sends a request to one specific device.But i am doing it manually because if all client devices clicks on a name of one specific device then it is OK with multiple connections.But now i need to do it programmatically so that one device automatically becomes group owner and all other devices should automatically send connection request to that specific device.Please help me with this problem.I am stuck at this point from last many days.Thanks in advance for your help.
What is the exact logic/problem there ?
Does it has to be fully automated ? or can the group owner selection be manual ?
In case all devices start the connections same time, then you must really do either manual selection, or have the devices somehow negotiate how they are selecting the group owner. Selection case you be really easy:
Group owner uses createGroup to create the group for connection
Group owner adds local service, and starts Peers Discovery and keeps it running (generally my research has shown that if there is no active connection, or peer discovery, the device local service is invisible for other dervices)
Clients, simply do Peer & Service discovery and do the connections
if there is possibility that the devices appear is same place different times, then of course the logic for fully automatic would be simple.
First all devices advertise & search for devices same time
with The first connection one device is set as Group owner and the other gets to be client
Both devices stop Peer & service discoveries
The Client device stops advertising the service, thus making the Group owner only visible service for any devices appearing into the vicinity, thus they would be connecting to it.
Anyways, I would have small example project which might help you at: Thali/WDConApp, anyways, with WiFi-Direct you would need to manually allow connections, You would try doing the pairing as I explained in my Blog, though I have to admit that since tuesday this week, I'm not so sure if it really works that way. I would need to do some additional tests (when I have time) to verify that I would actually know how it behaves.
Then, if you don't want to have the manual user acceptance of the dialogs, I would have two options for you. You could use unsecured Bluetooth connection as is used in Thali/BtConApp, or you could use WiFi Direct Access points for connectivity.
Note that Using the access point connectivity, will cut off any other WiFi connections. I do have example for it as well, and I actually uploaded it while writing this reply and you can find it from Thali/WAPConApp. Note that its just my first test version, and I'll likely do loads more work on improving it.

android wifi p2p : peers discovery filtering

I'm implementing the wifi p2P (direct wifi) in my android application, in order to share small files between clients.
I'm following these pretty good tutorials:
http://developer.android.com/guide/topics/connectivity/wifip2p.html
http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html
I can now discover peers and connect to them.
I'd like to know if there is a way to filter the discovered peers. The first thing I'd like is to show only the peers who are using the same application. Indeed, currently my application show me all peers (phones, tablets, printers with direct wifi). I think it would be easier for the user to only have the compatible peers (peers also using the application).
If this work, I'd like to improve this and only show peers who ave accepted to share their files (a client can receive files or/and share their own files if he had activated it)
So, is it possible to do these types of peer filtering?
Thank you.
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
Take a look here.
So using NSD your app will only see devices that supports the services your app requests, cool isn't it..?
I will get back to you if I come up with some intelligent logic for the second part.

Android WiFiDirect service discovery confusion

I'm trying to use WiFi Direct service discovery to connect two android phones. I'm only interested in one phone being able to send a connection request. I thought what I needed to do was register a local service on one phone, and discover the service on the other phone, and after discovering it I can connect to it. But it seems like I have to do the discovery stuff on both phones in order for it to work...so I'm just confused on what's happening. I'm using this tutorial. Can anyone help me understand what's necessary to have the two phones connect? I can't have one phone only registering and the other phone only discovering?
It really depends on what you are trying to do. You can actually discover other devices and perform a connection without having a Service Discovery layer on top. Peer Discovery and Service discovery are not the same thing. Peer discovery involves detecting all of the nearby devices that use Wifi Direct while Service Discovery involves only discovering devices that advertise a specific kind of service.
You should start with this other Tutorial before moving on to Service Discovery which is a more advanced topic.
You can detect other devices using peer discovery but there is no need for service discovery to exchange data or service. You can use socket connection also after connecting the devices ex - for exchanging of files .
It's worth to mention that using ServiceDiscovery you can sent some additional data, like running port or something else in record map (in DNS-SD at least).

Categories

Resources