如何:在 GKSession 中实现服务器强制断开客户端连接
我正在 iOS 上的应用程序中实现 GKSession 服务器/客户端模式操作。我发现一个 与以下内容相关的问题我的但没有答案。我试图允许服务器断开当前连接到会话的任何客户端的连接。我认为调用disconnectPeerFromAllPeers:(NSString *)peerID 可以让我做到这一点,但似乎没有效果。
有什么建议吗?
谢谢
I am implementing the GKSession server/client mode operation in my application on iOS. I found one question related to mine but with no answer. I am trying to allow the server to disconnect any client that is currently connected to the session. I thought that calling disconnectPeerFromAllPeers:(NSString *)peerID would allow me to do this, but is seems to have no effect.
Any suggestions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上是通过问题更新离子 01/03/2012 回答的,但将此文本移至答案部分
我想分享如何实现从服务器发送到客户端的断开连接请求。下面提供的所有代码都包含在我创建的一个类中,该类完全封装了与 GKSession 实例的所有接口(还实现了 GKSessionDelegate 方法)。
首先,我让服务器向应断开连接的客户端发送断开连接请求。从客户端发送到服务器(反之亦然)的任何数据都包含在一个字典中,该字典还具有一个键值对来指定发送的数据类型(在本例中,数据是断开连接请求)。
客户端接收数据,将其转换为字典并检查指定发送的数据类型的键值对。如果是断开连接请求,我的“GKSessionManager”类就会实现断开连接。
用户永远不会看到断开连接请求,因此无法控制是否拒绝它。
希望这些信息有帮助。我意识到我写的内容并不完全清楚,并且我(故意)遗漏了很多其他代码,因此请随意发表评论或提出问题。
Actually answered via question update ion 01/03/2012, but moved this text to the answer section
I wanted to share how I implemented a disconnect request sent from server to client. All of the code presented below is contained within a class I created to completely encapsulate all the interfacing with a GKSession instance (also implements the GKSessionDelegate methods).
First I have the server send a disconnect request to the client that shall be disconneted. Any data that is sent from client to server or vice versa is contained within a dictionary that also has a key-value pair to specify the type of data that is sent (in this case the data is a disconnect request).
The client receives the data, casts it into a dictionary and examines the key-value pair that specifies what type of data was sent. If it's a disconnect request, my "GKSessionManager" class then implements a disconnect.
The user never sees the disconnect request and so has no control over whether or not to deny it.
Hope this information helps. I realize what I wrote my not be entirely clear and I have left a lot of other code out (on purpose) so feel free to comment or ask questions.