Inheritance: global::System.IDisposable
        void Start()
        {
            if (this.PairingRole == Role.Connector)
            {
                this.pairMaker = new DirectPairConnector(this.RemoteAddress, this.RemotePort);
            }
            else
            {
                this.pairMaker = new DirectPairReceiver(this.LocalPort);
            }

            this.pairingAdapter = new PairingAdapter();
            this.pairingAdapter.SuccessEvent += OnPairingConnectionSucceeded;
            this.pairingAdapter.FailureEvent += OnPairingConnectionFailed;

            // Register to listen for disconnections, so we can reconnect automatically
            if (SharingStage.Instance != null)
            {
                this.sharingMgr = SharingStage.Instance.Manager;

                if (this.sharingMgr != null)
                {
                    this.connectionAdapter = new NetworkConnectionAdapter();
                    this.connectionAdapter.DisconnectedCallback += OnDisconnected;

                    NetworkConnection pairedConnection = this.sharingMgr.GetPairedConnection();
                    pairedConnection.AddListener((byte)MessageID.StatusOnly, this.connectionAdapter);
                }
            }

            StartPairing();
        }
        protected void OnDestroy()
        {
            Instance = null;

            // Force a disconnection so that we can stop and start Unity without connections hanging around
            this.sharingMgr.GetPairedConnection().Disconnect();
            this.sharingMgr.GetServerConnection().Disconnect();

            // Release the XTools manager so that it cleans up the C++ copy
            this.sharingMgr.Dispose();
            this.sharingMgr = null;

            // Forces a garbage collection to try to clean up any additional reference to SWIG-wrapped objects
            System.GC.Collect();
        }
        private void Awake()
        {
            Instance = this;

            this.logWriter = new ConsoleLogWriter();

            ClientConfig config = new ClientConfig(this.ClientRole);
            config.SetIsAudioEndpoint(this.IsAudioEndpoint);
            config.SetLogWriter(this.logWriter);
            config.SetServerAddress(this.ServerAddress);
            config.SetServerPort(this.ServerPort);
            config.SetProfilerEnabled(false);

            this.sharingMgr = SharingManager.Create(config);
        }
        private void Connect()
        {
            ClientConfig config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);
            config.SetServerAddress(ServerAddress);
            config.SetServerPort(ServerPort);
            config.SetProfilerEnabled(false);

            sharingMgr = SharingManager.Create(config);

            //set up callbacks so that we know when we've connected successfully
            networkConnection        = sharingMgr.GetServerConnection();
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
            networkConnection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);
        }
        protected override void OnDestroy()
        {
            if (discoveryClient != null)
            {
                discoveryClient.RemoveListener(discoveryClientAdapter);
                discoveryClient.Dispose();
                discoveryClient = null;

                if (discoveryClientAdapter != null)
                {
                    discoveryClientAdapter.Dispose();
                    discoveryClientAdapter = null;
                }
            }

            if (networkConnection != null)
            {
                networkConnection.RemoveListener((byte)MessageID.StatusOnly, networkConnectionAdapter);
                networkConnection.Dispose();
                networkConnection = null;

                if (networkConnectionAdapter != null)
                {
                    networkConnectionAdapter.Dispose();
                    networkConnectionAdapter = null;
                }
            }

            if (sharingMgr != null)
            {
                // Force a disconnection so that we can stop and start Unity without connections hanging around
                sharingMgr.GetPairedConnection().Disconnect();
                sharingMgr.GetServerConnection().Disconnect();

                // Release the XTools manager so that it cleans up the C++ copy
                sharingMgr.Dispose();
                sharingMgr = null;
            }

            // Forces a garbage collection to try to clean up any additional reference to SWIG-wrapped objects
            GC.Collect();

            base.OnDestroy();
        }