如何区分客户端在iPhone上的主机的GameKit蓝牙 [英] How to tell the host from the client in iPhone bluetooth with GameKit

查看:145
本文介绍了如何区分客户端在iPhone上的主机的GameKit蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用的GameKit框架,其中2部iPhone / iPod播放器可以通过蓝牙相互连接并播放了一个多人游戏。

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

我想到了一个办法,选择哪个设备将可以先玩。因此,合理的解决方案是选择连接的主机。有没有连服务器,并在GKSession客户端?他们都是同龄人?哪条路线我将实现我需要什么?

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?

推荐答案

基本上,这是给你,你要配置您的会话。

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

从Apple文档:

会话发现在其他同龄人
  网络基于会话模式这
  当会话设置
  初始化。应用程序可以
  配置会话是一个服务器,
  该通告的服务类型
  网络;一个客户端,它搜索
  广告服务器;或对等体,
  通告像服务器和搜索
  就像一个客户端同时进行。

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.

您的应用程序的副本充当
  服务器通过初始化会话
  调用
  initWithSessionID:显示名:sessionMode:
  与会话模式要么
  GKSessionModeServer或
  GKSessionModePeer。之后
  应用程序配置会话,它
  通过设置通告服务
  会议的isAvailable属性为YES。

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.

您的应用程序的副本充当
  客户通过初始化会话
  调用
  initWithSessionID:显示名:sessionMode:
  与会话模式要么
  GKSessionModeClient或
  GKSessionModePeer。配置完
  会议期间,您的应用程序搜索
  网络广告服务器通过
  设置会话的isAvailable
  属性为YES。如果会话
  配置成与GKSessionModePeer
  会话模式还标榜自己
  作为服务器,如上所述

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.

因此​​,如果您使用GKSessionModePeer初始化会话,你同行(既作为服务器和客户端)。如果你想从客户区分服务器,具有GKSessionModeServer初始化。

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.

亲切的问候。

这篇关于如何区分客户端在iPhone上的主机的GameKit蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆