I have an Wifi Direct Android Application which will run on two Phones.
When phone1
connects to phone2
, I want phone1
to act as a client
and phone2
to act as a server
.
I used this code:
if (info.groupFormed && info.isGroupOwner) {
// start the server thread
} else if (info.groupFormed) {
// start the client thread
}
But the problem is that , sometimes phone1
which has initiated the connection and I want it to act as a client , it sometimes acts as a GroupOwner
, and the server thread is started on the client phone.
I want to make sure that phone2
always act as a GroupOwner
and a server
.
The group owner election is established through the group owner negotiation procedure, where devices exchange their Intent Value, which represents their willingness to act as a group owner. The device with a higher Intent Value is elected to be a group owner.
Wi-Fi Direct (also known as peer-to-peer or P2P) allows your application to quickly find and interact with nearby devices, at a range beyond the capabilities of Bluetooth. The Wi-Fi Direct (P2P) APIs allow applications to connect to nearby devices without needing to connect to a network or hotspot.
The device supported Wi-Fi Direct as standard, and it was automatically enabled, allowing anyone within range to connect.
How Does Wi-Fi Direct Work? Wi-Fi Direct doesn't require a centralized network or wireless router to share information between devices. Instead, when a connection is made, one device acts as the access point or hotspot. Other devices then connect to this original device using WPS and WPA/WPA2 protocols.
To set a peer as a client , not a GroupOWner
eachtime , we have to assign:
config.groupOwnerIntent = 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With