Ejemplo n.º 1
0
        public void Disconnect(bool onDestroy = false)
        {
            peer?.Disconnect();

            if (!onDestroy)
            {
                PortForwarder.ReleaseInstance();
            }
        }
Ejemplo n.º 2
0
        // *************** The Most Important API' s *************** //

        public void HostAndRegisterToMaster(string password)
        {
            if (!ConnectionToMaster.initMasterConn || peer == null)
            {
                return;
            }

            Host();

            PortForwarder.ReleaseInstance();

            this.localIP    = LocalNetworkUtils.GetLocalIPAddress();
            this.internalEP = new IPEndPoint(IPAddress.Parse(this.localIP), peer.GetPort());

            Debug.Log("Internal EP : " + this.internalEP);

            ConnectionToMaster.Instance.StartClient(() =>
            {
                RequestExternalEP(OnRequestExternalEP: (ep) =>
                {
                    this.externalEP = ep;
                    Debug.Log("Network Peer External : " + this.externalEP);

                    ConnectionToMaster.Instance.RegisterToMaster(this.internalEP, this.externalEP, password,
                                                                 (hostID) =>
                    {
                        peer.OnHosted();
                        // try to forward port in case hole punching does not work
                        if (usePortForwarding)
                        {
                            PortForwarder.Instance.ForwardPort(internalEP.Port, externalEP.Port);
                        }
                    });
                });
            });
        }