本文介绍了从MCSession断开个别对等体的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一组连接的对等体,让我们说3(a-> b,a-> c,a-> d)
我只想断开对等体c,我该怎么办?在做什么?

If I have an array of connected peers, let's say 3 (a->b, a->c, a->d)and I want to disconnect peer "c" only, what should I be doing?

我看到一个对类似问题的回复表明你只能断开自己与会话的关系:这意味着在上面的场景中,如果我这样做:

I've seen one response to a similar question state that you can only disconnect 'yourself' from a session: meaning that in the above scenario if I do this:

[mySession disconnect];

我同时从b,c和d同时断开a 。
所以建议是向你想要断开连接的对等体发送通知(c)并告诉它断开与会话的连接。

that I all be disconnecting "a" from "b", "c" and "d" simultaneously.So the suggestion was to send a notification to the peer you want disconnected ("c") and tell it to disconnect from the session.

然而,我我也看到了这个,并想知道它是否符合我的要求 - 仅删除特定的同行:

However, I've also seen this and wondered if it does what I'm asking - removes the specific peer only:

[mySession.connectedPeers[0] disconnect];

编辑:我刚刚意识到这是一个只读属性,所以忽略这一部分。

I just realized this is a read-only property, so ignore this portion.

或者还有另一种更好的方法可以删除特定的同行吗?

Or is there yet another, perhaps better way to remove specific peers?

推荐答案

每个对等连接由MCSession的实例表示。
因此在您的示例中,您将有3个指向MCSession对象的UNIQUE指针:

Each peer-to-peer connection is represented by an instance of MCSession.So in your example, you will have 3 UNIQUE pointers to MCSession objects:

MCSession *p1 = a->b
MCSession *p2 = a->c
MCSession *p3 = a->d

所以要断开对等c,你将:

so to disconnect peer c you will:

[p2 disconnect]; // release the session
p2 = nil; // release the resource

当然,您可以将会话存储在可变数组中,然后执行相同操作逻辑,但使用数组中的指针

Of course, you can store sessions in a mutable array and then do the same logic, but use the pointer from the array

p2 = (MCSession *)[array objectAtIndex:1];
[p2 disconnect];
[array removeObjectAtIndex:1];

这篇关于从MCSession断开个别对等体的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:50