Allows users of NetworkConnection to register to receive event callbacks without having their classes inherit directly from NetworkConnectionListener
Inheritance: NetworkConnectionListener
        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();
        }
Ejemplo n.º 2
0
        public XToolsApp(string[] args = null)
        {
            parsedArguments = ParseCommandLine(args);
            this.logWriter = new ConsoleLogWriter();

            ClientConfig config = new ClientConfig(ClientRole.Primary);
            config.SetServerAddress(GetArgumentOrDefault("sessionserver", "localhost"));
            config.SetLogWriter(this.logWriter);

            this.Manager = SharingManager.Create(config);
            this.syncListener = new ConsoleSyncReporter();

            this.viewerConnection = this.Manager.GetPairedConnection();
            this.serverConnection = this.Manager.GetServerConnection();
            this.SessionManager = this.Manager.GetSessionManager();

            BeginPairing();

            ViewerListener = new NetworkConnectionAdapter();
            ViewerListener.ConnectedCallback += this.OnViewerConnected;
            ViewerListener.ConnectionFailedCallback += this.OnViewerConnectionFailed;
            ViewerListener.DisconnectedCallback += this.OnViewerDisconnected;
            viewerConnection.AddListener((byte)MessageID.StatusOnly, ViewerListener);

            ServerListener = new NetworkConnectionAdapter();
            ServerListener.ConnectedCallback += this.OnSessionConnected;
            ServerListener.ConnectionFailedCallback += this.OnSessionConnectionFailed;
            ServerListener.DisconnectedCallback += this.OnSessionDisconnected;
            serverConnection.AddListener((byte)MessageID.StatusOnly, ServerListener);

            this.rootObject = this.Manager.GetRootSyncObject();
            this.rootObject.AddListener(this.syncListener);

            // Listen for new sessions
            SessionManagerListener = new XToolsSessionManagerListener();
            this.SessionManager.AddListener(SessionManagerListener);
        }