Пример #1
0
        public static async UniTask <Peer> ConnectPeerAsync(IPEndPoint ip, string peerid = "", int localport = 0)
        {
            foreach (var p in Peers)
            {
                if (Equals(p.IPEndPoint, ip) || p.ID == peerid)
                {
                    Debugger.Error("[UniP2PManager] Already Connected.");
                    return(null);
                }
            }

            if (Equals(ip, PrivateIPEndPoint) || Equals(ip, StunIPEndPoint))
            {
                Debugger.Error("[UniP2PManager] IPEndPoint is MySelf. :" + ip);
                return(null);
            }
            var peer = await Socket.ConnectPeerAsync(ip, peerid, localport);

            if (peer != null)
            {
                Debugger.Log("[UniP2PManager] Connected Peer id:" + peer.ID + " IPEndPoint:" + peer.IPEndPoint);
            }
            return(peer);
        }