gpt4 book ai didi

android - 为什么我作为客户端连接时客户端列表是空的?

转载 作者:行者123 更新时间:2023-11-29 01:18:37 25 4
gpt4 key购买 nike

我正在使用 Android Wi-Fi Direct 服务发现。当连接信息可用时,如果形成了一个组,我会请求组信息。出于某种原因,当我作为客户端连接时,我可以从组中获取组所有者,但客户端列表是空的。当我以群组所有者身份连接时,我可以获得群组所有者和客户列表。当我到达聊天 fragment 时,我试图显示群组所有者和客户是谁。另一个问题是组所有者设备名称似乎是空白,但其余信息是正确的,例如地址(我删除了地址行)。我试过在几个不同的地方请求组信息,但作为客户端连接时,我永远无法获得客户端列表。当我收到 SERVICE_CONNECTED Intent 时,我切换到聊天 fragment 。

作为客户端连接:

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

以群组所有者身份连接:

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

代码:

@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));
}

最佳答案

根据一位 Wi-Fi Direct 贡献者的说法,组客户端看不到其他客户端的列表。群组所有者必须跟踪并通知群组客户。

https://groups.google.com/forum/#!topic/wi-fi-direct/Ox83PKa1ilw

关于android - 为什么我作为客户端连接时客户端列表是空的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38187617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com