public void Disconnect(bool onDestroy = false) { peer?.Disconnect(); if (!onDestroy) { PortForwarder.ReleaseInstance(); } }
private void Awake() { if (_instance == null) { _instance = this; } else if (_instance != this) { Destroy(gameObject); } init = true; DontDestroyOnLoad(gameObject); }
// *************** 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); } }); }); }); }