我从未尝试过,但似乎您可以在客户Nearby.Connections.getLocalEndpointId()
端设备上获取客户端 endpointId。不确定这如何帮助向其他客户端发送消息,因为主机无论如何都知道 Client-EndpointIds ......
但是,作为概念证明,您可以执行以下操作:
在主机中:
String payload = client2EndpointId;
Nearby.Connections.sendReliableMessage(mGoogleApiClient, client1EndpointId, payload);
在客户端 1 中:
@Override
public void onMessageReceived(String endpointId, byte[] payload, boolean isReliable) {
String client2EndpointId = (String) payload;
Nearby.Connections.sendReliableMessage(mGoogleApiClient, client2EndpointId, messageFromClient1ToClient2);
}
在 Client2 中:
@Override
public void onMessageReceived(String endpointId, byte[] payload, boolean isReliable) {
String messageFromClient1 = (String) payload;
}
Host 将 client2 的 EndpointId 作为消息发送给 client1。然后,Client1 使用此 endpointId 向 client2 发送消息。