MatchMaker offers a utility function to help you start P2P communication with matched users.
MatchMaker and TeamMatchMaker class have a method to exchange client addresses to start P2P communication.
The example below uses MatchMaker class.
// This list keeps track of all P2P class instancesList<P2P> peers =newList<P2P>();// This event callback receives all matched clients' addressesmatchmaker.OnP2PAddressSync += (Diarkis.Lib.Packet.P2PClientAddr[] clients) =>{for (int i =0; i <clients.Length; i++) {Diarkis.Lib.Packet.P2PClientAddr addr =clients[i]; // diarkisUDPClient is the Diarkis UDP client instance // that is connected to the serverDiarkis.Modules.P2P peerClient =newDiarkis.Modules.P2P(diarkisUDPClient);peerClient.OnReady += OnP2PReady;peerClient.OnFail += OnP2PFail;peerClient.OnMessage += OnMessage;peerClient.Connect(addr.PublicAddr,addr.LocalAddr); // peers is used in Update methodpeers.Add(peerClient); }};private voidOnP2PReady(string peerAddress,int peerPort,double holePunchTimeInMilliseconds){ // P2P is now ready!}private voidOnP2PFail(string peerAddress,int peerPort){ // P2P has failed...}private voidOnMessage(string senderAddress,int senderPort, byte[] msg){ // Handle the message sent from another client}// For Unity Game Engine...voidUpdate(){ // We must call Update of each P2P class instanceslock(peers) {for (int i =0; i <peers.Count; i++) {peers[i].Update(); } }}// Calling this triggers OnP2PAddressSync event on all matched user clientsmatchmaker.P2PAddressSync();