策略
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Nearby Connections 支持不同的广告和发现策略。
要使用的最佳策略取决于用例。
集群
集群策略是一种对等策略,支持 M 对 N 或集群形连接拓扑。换句话说,这使得在无线电范围(约 100 米)内连接无定形的设备集群成为可能,其中每个设备既可以向 M 个其他设备发起出站连接,也可以接受来自 N 个其他设备的入站连接。
此策略在拓扑结构限制方面比星形策略更灵活,但会导致连接带宽较低。它非常适合有效负载较小且需要更像网状网络体验的使用场景,例如多人游戏。
加注星标
星形策略是一种对等策略,支持 1 对 N 或星形连接拓扑。换句话说,这使得无线电范围(约 100 米)内的设备能够以星形方式连接,其中每个设备在任何给定时间都可以充当中心(可以接受来自 N 个其他设备的传入连接)或辐条(可以向单个中心发起传出连接),但不能同时充当中心和辐条。
此策略最适合以下情况:一个设备进行通告,N 个设备发现通告者。不过,如果需要,您也可以同时进行通告和发现。
与集群策略相比,此策略在拓扑约束方面更为严格,但可实现更高带宽的连接。它非常适合高带宽使用场景,例如向一群好友分享视频。
从 A 点到 B 点
点对点策略是一种支持 1 对 1 连接拓扑的点对点策略。换句话说,此功能可实现无线电范围(约 100 米)内的设备以尽可能高的吞吐量进行连接,但一次只能建立一个连接。
此策略最适合以下情况:传输数据比灵活维护多个连接更重要。
此策略在拓扑约束方面比星形策略更严格,但可实现更高带宽的连接。它非常适合高带宽使用情形,例如将大型视频分享到另一台设备。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-13。
[null,null,["最后更新时间 (UTC):2025-08-13。"],[[["\u003cp\u003eNearby Connections offers three connection strategies: Cluster, Star, and Point-to-Point, each designed for different use cases and connection topologies.\u003c/p\u003e\n"],["\u003cp\u003eThe Cluster strategy enables connections between multiple devices within radio range, ideal for mesh-like experiences with smaller payloads, like multiplayer gaming.\u003c/p\u003e\n"],["\u003cp\u003eThe Star strategy allows a central device (hub) to connect with multiple other devices (spokes), best suited for scenarios with one advertiser and multiple discoverers, offering higher bandwidth suitable for video sharing.\u003c/p\u003e\n"],["\u003cp\u003eThe Point-to-Point strategy focuses on high-bandwidth, one-to-one connections, prioritizing data transfer speed over maintaining multiple connections, ideal for sharing large files.\u003c/p\u003e\n"]]],[],null,["# Strategies\n\nNearby Connections supports different strategies for advertising and discovery.\nThe best strategy to use depends on the use case.\n\nCluster\n-------\n\nThe cluster strategy is a peer-to-peer strategy that supports an M-to-N, or\ncluster-shaped, connection topology. In other words, this enables connecting\namorphous clusters of devices within radio range (\\~100m), where each device can\nboth initiate outgoing connections to M other devices and accept incoming\nconnections from N other devices.\n\nThis strategy is more flexible in its topology constraints than the star\nstrategy, but results in lower bandwidth connections. It is good for use cases\nwith smaller payloads that require a more mesh-like experience, such as\nmultiplayer gaming.\n\nStar\n----\n\nThe star strategy is a peer-to-peer strategy that supports a 1-to-N, or\nstar-shaped, connection topology. In other words, this enables connecting\ndevices within radio range (\\~100m) in a star shape, where each device can, at\nany given time, play the role of either a hub (where it can accept incoming\nconnections from N other devices), or a spoke (where it can initiate an outgoing\nconnection to a single hub), but not both.\n\nThis strategy lends itself best to situations where there is one device\nadvertising, and N devices which discover the advertiser, though you may still\nadvertise and discover simultaneously if required.\n\nThis strategy is more strict in its topology constraints than the cluster\nstrategy, but results in higher bandwidth connections. It is good for\nhigh-bandwidth use cases such as sharing a video to a group of friends.\n\nPoint-to-Point\n--------------\n\nThe point-to-point strategy is a peer-to-peer strategy that supports a 1-to-1\nconnection topology. In other words, this enables connecting devices within\nradio range (\\~100m) with the highest possible throughput, but does not allow for\nmore than a single connection at a time.\n\nThis strategy lends itself best to situations where transferring data is more\nimportant than the flexibility of maintaining multiple connections.\n\nThis strategy is more strict in its topology constraints than the star strategy,\nbut results in higher bandwidth connections. It is good for high-bandwidth use\ncases such as sharing a large video to another device."]]