我有一个应用程序,将运行在两部手机上。
当phone1连接到phone2时,我希望phone1充当client,phone2充当server。
我使用了这个代码:
if (info.groupFormed && info.isGroupOwner) {
// start the server thread
} else if (info.groupFormed) {
// start the client thread
}但问题是,有时启动连接的phone1 --我希望它充当客户机--有时充当GroupOwner,服务器线程在客户端电话上启动。
我想确保phone2始终充当GroupOwner和server的角色。
发布于 2013-09-09 19:12:22
若要将对等方设置为客户端,而不是每个时间的GroupOWner,我们必须分配:
config.groupOwnerIntent = 0;发布于 2015-03-16 16:26:59
你能做的就是:
@Override
public void connect(final WifiP2pDevice device) {
//obtain a peer from the WifiP2pDeviceList
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
config.wps.setup = WpsInfo.PBC;
config.groupOwnerIntent = 15; // I want this device to become the owner
mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
//success logic
Log.d(P2P, "connected to device " + device.deviceName);
}
@Override
public void onFailure(int reason) {
//failure logic
Log.d(P2P, "unable to establish connection to device " + device.deviceName);
}
});
}注意config.groupOwnerIntent = 15;行。这告诉WifiP2pConfig,我们这个连接的设备更有可能成为GroupOwner。
这里博士
希望能帮上忙。
https://stackoverflow.com/questions/18703881
复制相似问题