如何使用 GameKit 在 iPhone 蓝牙中区分主机和客户端

发布于 2024-07-25 13:11:41 字数 173 浏览 4 评论 0原文

我使用 GameKit 框架制作了一款多人游戏,其中 2 个 iPhone/iPod 可以通过蓝牙相互连接并玩。

我正在考虑一种方法来选择哪个设备可以先播放。 因此,合理的解决方案是选择连接的主机。 GKSession 中是否有服务器和客户端? 他们都是同龄人吗? 我该走哪条路才能达到我的需要?

I have made a multiplayer game using the GameKit Framework where 2 iPhones/iPods can connect to each other via bluetooth and play.

I am thinking of a way to choose which device will be able to play first. So the logical solution is to pick the host of the connection. Is there even a server and a client in the GKSession? Are they all peers? Which route shall I take to achieve what I need?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白鸥掠海 2024-08-01 13:11:41

基本上,您可以根据自己的喜好配置会话。

来自苹果文档:

会话发现网络上的其他对等点
基于会话模式的网络
会话时设置
已初始化。 您的应用程序可以
将会话配置为服务器,
它在上发布服务类型
网络; 一个客户端,它搜索
广告服务器; 或同伴,其中
像服务器一样做广告和搜索
同时就像一个客户。

作为您的申请的副本
服务器通过以下方式初始化会话
呼叫
initWithSessionID:显示名称:会话模式:
会话模式为
GKSessionModeServer 或
GKSessionModePeer。 之后
应用程序配置会话,它
通过设置来宣传该服务
会话的 isAvailable 属性设置为 YES。

作为您的申请的副本
客户端通过以下方式初始化会话
呼叫
initWithSessionID:显示名称:会话模式:
会话模式为
GKSessionModeClient 或
GKSessionModePeer。 配置后
会话中,您的应用程序搜索
广告服务器网络
设置会话的 isAvailable
属性为 YES。 如果会话是
使用 GKSessionModePeer 配置
会话模式它也宣传自己
作为服务器,如上所述。

因此,如果您使用 GKSessionModePeer 来初始化会话,您就拥有了对等点(既充当服务器又充当客户端)。 如果您想区分服务器和客户端,请使用 GKSessionModeServer 对其进行初始化。

亲切的问候。

Basically, it is up to you to configure your session as you like.

From the Apple documentation:

Sessions discover other peers on the
network based on a session mode which
is set when the session is
initialized. Your application can
configure the session to be a server,
which advertises a service type on the
network; a client, which searches for
advertising servers; or a peer, which
advertises like a server and searches
like a client simultaneously.

A copy of your application acting as a
server initializes the session by
calling
initWithSessionID:displayName:sessionMode:
with a session mode of either
GKSessionModeServer or
GKSessionModePeer. After the
application configures the session, it
advertises the service by setting the
session’s isAvailable property to YES.

A copy of your application acting as a
client initializes the session by
calling
initWithSessionID:displayName:sessionMode:
with a session mode of either
GKSessionModeClient or
GKSessionModePeer. After configuring
the session, your application searches
the network for advertising servers by
setting the session’s isAvailable
property to YES. If the session is
configured with the GKSessionModePeer
session mode it also advertises itself
as a server, as described above.

Therefore, if you use GKSessionModePeer to initialize the session, you have peers (acting both as server and client). If you want to distinguish a server from its clients, initialize it with GKSessionModeServer.

Kind regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文