I'm using Android Wi-Fi Direct service discovery. When connection info is available, I request group info if a group is formed. For some reason, when I connect as a client, I can get the group owner from the group, but the client list is empty. When I connect as a group owner, I'm able to get the group owner and the client list. When I get to the chat fragment, I'm trying to display who the group owner and clients are. Another issue is that the group owner device name seems to be blank, but the rest of the info is correct, like the address (I removed the address lines). I've tried requesting group info in a few different places, and I'm never able to get the client list when connected as a client. I switch to the chat fragment when I receive the SERVICE_CONNECTED
intent.
Connecting as client:
I/wfd_: Wi-Fi P2P Connection Changed
I/wfd_: Connected to P2P network. Requesting connection info
I/wfd_: Connection info available
I/wfd_: WifiP2pInfo:
I/wfd_: Group formed: true
Is group owner: false
Group owner address: /192.168.49.1
I/wfd_: Stopping service discovery
I/wfd_: Service discovery stopped
I/wfd_: Connected as client
I/wfd_: Requesting group info
I/wfd_CommReceiver: This device changed
I/wfd_ClientSocketHandler: Client socket thread running
I/wfd_ClientSocketHandler: Opening client socket
I/System.out: [CDS][DNS] getAllByNameImpl netId = 0
I/System.out: [socket][0] connection /192.168.49.1:4545;LocalPort=34789(5000)
I/System.out: [CDS]connect[/192.168.49.1:4545] tm:5
I/wfd_: Service discovery requests cleared
I/wfd_: Group info available
I/wfd_: WifiP2pGroup:
I/wfd_: Network name: DIRECT-Ig-BLU Clark 2
Is group owner: false
Group owner:
Device name: BLU Clark 2
Status: Unavailable
Client list is empty.
/System.out: [socket][/192.168.49.117:34789] connected
I/wfd_ClientSocketHandler: Client socket - true
I/wfd_ClientSocketHandler: Launching the I/O handler
I/wfd_CommReceiver: Service connected
I/wfd_CommReceiver: Switching to Chat fragment
I/wfd_: handleMessage() called
Connecting as group owner:
I/wfd_: Wi-Fi P2P Connection Changed
I/wfd_: Connected to P2P network. Requesting connection info
I/wfd_: Connection info available
I/wfd_: WifiP2pInfo:
I/wfd_: Group formed: true
Is group owner: true
Group owner address: /192.168.49.1
I/wfd_: Stopping service discovery
I/wfd_: Service discovery stopped
I/wfd_: Connected as group owner
I/wfd_OwnerSocketHandler: Group owner server socket started
I/wfd_: Requesting group info
I/wfd_OwnerSocketHandler: Group owner server socket thread running
I/wfd_: Service discovery requests cleared
I/wfd_CommReceiver: This device changed
I/wfd_: Group info available
I/wfd_: WifiP2pGroup:
I/wfd_: Network name: DIRECT-XB-Brendan BLU
Is group owner: true
Group owner:
Device name:
Status: Unavailable
Client:
Device name: BLU Clark 2
Status: Connected
I/wfd_CommReceiver: Service connected
I/wfd_CommReceiver: Switching to Chat fragment
I/wfd_OwnerSocketHandler: Launching the I/O handler
I/wfd_: handleMessage() called
Code:
@Override
public void onConnectionInfoAvailable(WifiP2pInfo wifiP2pInfo) {
Log.i(TAG, "Connection info available");
Log.i(TAG, "WifiP2pInfo: ");
Log.i(TAG, p2pInfoToString(wifiP2pInfo));
this.groupFormed = wifiP2pInfo.groupFormed;
this.isGroupOwner = wifiP2pInfo.isGroupOwner;
if (wifiP2pInfo.groupFormed) {
stopServiceDiscovery();
Thread handler;
if (wifiP2pInfo.isGroupOwner) {
Log.i(TAG, "Connected as group owner");
try {
handler = new OwnerSocketHandler(this.getHandler());
handler.start();
} catch (IOException e) {
Log.e(TAG, "Failed to create a server thread - " + e.getMessage());
return;
}
} else {
Log.i(TAG, "Connected as client");
handler = new ClientSocketHandler(this.getHandler(), wifiP2pInfo.groupOwnerAddress);
handler.start();
}
Log.i(TAG, "Requesting group info");
// Requests peer-to-peer group information
wifiP2pManager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup wifiP2pGroup) {
Log.i(TAG, "Group info available");
if (wifiP2pGroup != null) {
Log.i(TAG, "WifiP2pGroup:");
Log.i(TAG, p2pGroupToString(wifiP2pGroup));
WifiDirectHandler.this.wifiP2pGroup = wifiP2pGroup;
} else {
Log.w(TAG, "Group is null");
}
localBroadcastManager.sendBroadcast(new Intent(Action.SERVICE_CONNECTED));
}
});
} else {
Log.w(TAG, "Group not formed");
}
localBroadcastManager.sendBroadcast(new Intent(Action.DEVICE_CHANGED));
}
According to one of the Wi-Fi Direct contributors, a group client cannot see a list of the other clients. The group owner would have to keep track of that and inform the group clients.
https://groups.google.com/forum/#!topic/wi-fi-direct/Ox83PKa1ilw