If two clients each called A and B wish to P2P communicate then they need to be members of at least one of the same P2P group.
In typical internet messenger service :
Several people can chat all together in one chatting window,
can bring as many chatting windows as you want for multi-chatting,
but can't chat unless you are in either one of those chatting windows.
P2P Group of ProudNet is also in the same concept. In internet messenger, each chatting windows respond to their associated P2P groups. Only difference is the authority of creating chatting window or entering a chatting window is given to server.
Identifier of P2P group is also Proud.HostID type.
12.1Creating a new P2P group
If you want to start P2P communication with other clients in ProudNet then you need to create a P2P group from server first. You can create a P2P group from server with Proud.CNetServer.CreateP2PGroup.
When a P2P group is created from server, client receives Proud.INetClientEvent.OnP2PMemberJoin event for members of P2P group (HostID of clients within the group).
When client manages Proud.INetClientEvent.OnP2PMemberJoin, server will receive Proud.INetServerEvent.OnP2PGroupJoinMemberAckComplete. This event is effective when server wants to manage something else after every client detecting the change made for their P2P group in server.
12.2Adding a new client to P2P groupP2P
If you wish to add a new client as a member to an already existing P2P group, you can do so with Proud.CNetServer.JoinP2PGroup.
Then client receives Proud.INetClientEvent.OnP2PMemberJoin and Proud::INetServerEvent::OnP2PGroupJoinMemberAckComplete from server shortly after. The process of this is same as the event of 12.1 Creating a new P2P group.
12.3Kicking out a client from P2P group
When you want to kick out a member from P2P group then Proud.CNetServer.LeaveP2PGroup does the trick.
When a member gets kicked out, the remaining members of P2P group receive Proud.INetClientEvent.OnP2PMemberLeave while the kicked out client receives Proud.INetClientEvent.OnP2PMemberLeave.
If client disconnects from server, he or she will be kicked out from P2P group automatically.
Even though there is no one left in P2P group, P2P group itself doesn't get perished but just stays empty. If you want to delete P2P group permanently then you need to use Proud.CNetServer.DestroyP2PGroup.
There is also a way to set P2P group to self-perish automatically. For more details, please refer to Proud.CNetServer.AllowEmptyP2PGroup.
12.4Deleting a P2P group
If you wish to delete a P2P group from server, you can do so with Proud.CNetServer.DestroyP2PGroup.
When P2P group is deleted, all clients included in the P2P group will receive Proud.INetClientEvent.OnP2PMemberLeave for all members.
You can use Proud.CNetServer.DestroyEmptyP2PGroups to delete all P2P groups with no members whatsoever.