Я пишу приложение для Android, которое использует Wifi Direct.Когда приложение работает на нескольких устройствах, одно из них создаст группу, вызвав этот код:
mManager.createGroup(mChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
// Device is ready to accept incoming connections from peers.
}
@Override
public void onFailure(int reason) {
}
});
Затем другие устройства вызывают этот код для подключения к этому устройству, чтобы впоследствии они могли отправлять на него данные.через сокет TCP:
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = groupOwnerDevice.deviceAddress;
config.wps.setup = WpsInfo.PBC;
mManager.connect(mChannel, config, new ActionListener() {
@Override
public void onSuccess() {
// WiFiDirectBroadcastReceiver notifies us. Ignore for now.
}
@Override
public void onFailure(int reason) {
}
});
После подключения я получаю IP-адрес владельца группы, чтобы впоследствии использовать его для создания сокета TCP из моей реализации WifiP2pManager.ConnectionInfoListener
:
@Override
public void onConnectionInfoAvailable(final WifiP2pInfo info)
{
// InetAddress from WifiP2pInfo struct (the IP address).
InetAddress groupOwnerAddress = info.groupOwnerAddress.getHostAddress();
// After the group negotiation, we can determine the group owner
// (server).
if (info.groupFormed && info.isGroupOwner) {
// Do whatever tasks are specific to the group owner.
// One common case is creating a group owner thread and accepting
// incoming connections.
} else if (info.groupFormed) {
// The other device acts as the peer (client). In this case,
// you'll want to create a peer thread that connects
// to the group owner.
}
}
У меня вопрос, в какой момент info.groupFormed
равно истинно?Что это значит?Почему это было бы ложным?Это даже важно, или я могу просто проигнорировать это?
Я следую документации здесь: https://developer.android.com/training/connect-devices-wirelessly/wifi-direct