/// <summary> /// Uninitializes this instance. Cleanup refernces here. /// </summary> protected void Uninitialize() { StopCoroutine("_listener.Listen"); StopCoroutine("RequestMessage"); //_listener.Stop(); Disconnect(); OCPortManager.ReleasePort(_port); }
protected void InitializeNetworkElement(string id) { UnityEngine.Debug.Log("In InitializeNetworkElement, my GUID is " + VerificationGuid); _ID = id; _port = OCPortManager.AllocatePort(); _IP = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0]; // routerIpString appears to only be set in the obsoleted OldNetworkElement class in the old project... //_routerIP = IPAddress.Parse(this.routerIpString); // so we'll try the new way for now string strConfigIP = OCConfig.Instance.get("ROUTER_IP", "192.168.1.48"); _routerIP = IPAddress.Parse(strConfigIP); _routerPort = OCConfig.Instance.getInt("ROUTER_PORT", 16312); // if (_routerIP.ToString() == string.Empty) // { // _routerIP = IPAddress.Parse ("158.132.219.182"); // _routerPort = 16312; // UnityEngine.Debug.Log ("Using hardcoded IP: " + _routerIP.ToString() + ":" + _routerPort); // } OCServerListener.Instance.Initialize(this); _listener = OCServerListener.Instance; StartCoroutine(Connect()); UnityEngine.Debug.Log("StartCoroutine(_listener.Listen())"); if (bool.Parse(OCConfig.Instance.get("GENERATE_TICK_MESSAGE"))) { UnityEngine.Debug.Log("Generation of tick messages is enabled."); } //StartCoroutine(_listener.Listen()); //StartCoroutine(RequestMessage(1)); }
protected void InitializeNetworkElement(string id) { UnityEngine.Debug.Log("In InitializeNetworkElement, my GUID is " + VerificationGuid); _ID = id; _port = OCPortManager.AllocatePort(); // Temporarily reverted to: _IP = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0]; // See: https://github.com/opencog/unity3d-opencog-game/issues/15#issuecomment-36709935 // // http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c // IEnumerable<NetworkInterface> networkInterfaces = // from entry in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() // where entry.OperationalStatus.Equals (OperationalStatus.Up) // select entry; // // foreach (NetworkInterface networkInterface in networkInterfaces) // { // IPInterfaceProperties ipProperties = networkInterface.GetIPProperties(); // UnicastIPAddressInformationCollection unicastAddresses = ipProperties.UnicastAddresses; // // foreach (UnicastIPAddressInformation unicastAddress in unicastAddresses) // { // if (unicastAddress.DuplicateAddressDetectionState == DuplicateAddressDetectionState.Preferred && // unicastAddress.AddressPreferredLifetime != System.UInt32.MaxValue) // _IP = unicastAddress.Address; // } // } UnityEngine.Debug.Log("IP Address detected: " + _IP); // routerIpString appears to only be set in the obsoleted OldNetworkElement class in the old project... //_routerIP = IPAddress.Parse(this.routerIpString); // so we'll try the new way for now string strConfigIP = OCConfig.Instance.get("ROUTER_IP", "192.168.1.48"); _routerIP = IPAddress.Parse(strConfigIP); _routerPort = OCConfig.Instance.getInt("ROUTER_PORT", 16312); // if (_routerIP.ToString() == string.Empty) // { // _routerIP = IPAddress.Parse ("158.132.219.182"); // _routerPort = 16312; // UnityEngine.Debug.Log ("Using hardcoded IP: " + _routerIP.ToString() + ":" + _routerPort); // } OCServerListener.Instance.Initialize(this); _listener = OCServerListener.Instance; StartCoroutine(Connect()); UnityEngine.Debug.Log("StartCoroutine(_listener.Listen())"); if (bool.Parse(OCConfig.Instance.get("GENERATE_TICK_MESSAGE"))) { UnityEngine.Debug.Log("Generation of tick messages is enabled."); } //StartCoroutine(_listener.Listen()); //StartCoroutine(RequestMessage(1)); }