什么时候groupFormed等于true?

时间:2019-02-09 02:22:05

标签: android wifip2p

我正在编写一个使用Wifi Direct的Android应用程序。当多个设备运行该应用程序时,其中一个将通过调用以下代码来创建组:

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地址,以便以后可以通过我的WifiP2pManager.ConnectionInfoListener实现使用它来创建TCP套接字:

@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

0 个答案:

没有答案