Specifies options for interacting with a VNC client.
Esempio n. 1
0
        /// <summary>
        /// Starts a session with a VNC client.
        /// </summary>
        /// <param name="stream">The stream containing the connection.</param>
        /// <param name="options">Session options, if any.</param>
        /// <param name="startThread">A value indicating whether to start the thread.</param>
        /// <param name="forceConnected">A value indicated whether to immediately set <see cref="IsConnected"/>. Intended for unit tests only.</param>
        public void Connect(Stream stream, VncServerSessionOptions options = null, bool startThread = true, bool forceConnected = false)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            lock (this.c.SyncRoot)
            {
                this.Close();

                this.options  = options ?? new VncServerSessionOptions();
                this.c.Stream = stream;

                if (startThread)
                {
                    this.threadMain = new Thread(this.ThreadMain);
                    this.threadMain.IsBackground = true;
                    this.threadMain.Start();
                }

                if (forceConnected)
                {
                    this.IsConnected = true;
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Listening on local port 5900.");
            Console.WriteLine("Try to connect! The password is: {0}", Password);

            // Wait for a connection.
            var listener = new TcpListener(IPAddress.Any, 5900);
            listener.Start();
            var client = listener.AcceptTcpClient();

            // Set up a framebuffer and options.
            var options = new VncServerSessionOptions();
            options.AuthenticationMethod = AuthenticationMethod.Password;

            // Create a session.
            Session = new VncServerSession();
            Session.Connected += HandleConnected;
            Session.ConnectionFailed += HandleConnectionFailed;
            Session.Closed += HandleClosed;
            Session.PasswordProvided += HandlePasswordProvided;
            Session.SetFramebufferSource(new VncScreenFramebufferSource("Hello World", Screen.PrimaryScreen));
            Session.Connect(client.GetStream(), options);

            // Let's go.
            Application.Run();
        }
Esempio n. 3
0
        /// <summary>
        /// The main loop of the VNC server. Listens for new connections, and spawns new <see cref="VncServerSession"/>s.
        /// </summary>
        /// <returns>
        /// A <see cref="Task"/> which represents the asynchronous operation.
        /// </returns>
        protected async Task Run()
        {
            while (true)
            {
                var client = await this.listener.AcceptTcpClientAsync();

                // Set up a framebuffer and options.
                var options = new VncServerSessionOptions();
                options.AuthenticationMethod = AuthenticationMethod.Password;

                // Create a session.
                var session = new VncServerSession(
                    new VncPasswordChallenge(),
                    this.logger);

                session.Connected        += this.OnConnected;
                session.Closed           += this.OnClosed;
                session.PasswordProvided += this.OnPasswordProvided;
                session.SetFramebufferSource(this.framebufferSource);
                session.Connect(client.GetStream(), options);

                if (this.keyboard != null)
                {
                    session.KeyChanged += this.keyboard.HandleKeyEvent;
                }

                if (this.controller != null)
                {
                    session.PointerChanged += this.controller.HandleTouchEvent;
                }

                this.sessions.Add(session);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Starts a session with a VNC client.
        /// </summary>
        /// <param name="stream">The stream containing the connection.</param>
        /// <param name="options">Session options, if any.</param>
        public void Connect(Stream stream, VncServerSessionOptions options = null)
        {
            Throw.If.Null(stream, "stream");

            lock (this.c.SyncRoot)
            {
                this.Close();

                this.options  = options ?? new VncServerSessionOptions();
                this.c.Stream = stream;

                this.threadMain = new Thread(this.ThreadMain);
                this.threadMain.IsBackground = true;
                this.threadMain.Start();
            }
        }
        /// <summary>
        /// Starts a session with a VNC client.
        /// </summary>
        /// <param name="stream">The stream containing the connection.</param>
        /// <param name="options">Session options, if any.</param>
        public void Connect(TcpClient tcpClient, VncServerSessionOptions options = null)
        {
            _vncTcpClient = tcpClient;
            Stream stream = tcpClient.GetStream();

            Throw.If.Null(stream, "stream");

            lock (_c.SyncRoot)
            {
                Close();

                _options  = options ?? new VncServerSessionOptions();
                _c.Stream = stream;

                _threadMain = new Thread(ThreadMain);
                _threadMain.IsBackground = true;
                _threadMain.Start();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Starts a session with a VNC client.
        /// </summary>
        /// <param name="stream">The stream containing the connection.</param>
        /// <param name="options">Session options, if any.</param>
        /// <param name="startThread">A value indicating whether to start the </param>
        /// <param name="forceConnected">A value indicated whether to immediately set <see cref="IsConnected"/>. Intended for unit tests only.</param>
        public void Connect(Stream stream, VncServerSessionOptions options = null, bool startThread = true, bool forceConnected = false)
        {
            Throw.If.Null(stream, "stream");

            lock (this.c.SyncRoot)
            {
                this.Close();

                this.options  = options ?? new VncServerSessionOptions();
                this.c.Stream = stream;

                if (startThread)
                {
                    this.threadMain = new Thread(this.ThreadMain);
                    this.threadMain.IsBackground = true;
                    this.threadMain.Start();
                }

                if (forceConnected)
                {
                    this.IsConnected = true;
                }
            }
        }
        /// <summary>
        /// Starts a session with a VNC client.
        /// </summary>
        /// <param name="stream">The stream containing the connection.</param>
        /// <param name="options">Session options, if any.</param>
        public void Connect(Stream stream, VncServerSessionOptions options = null)
        {
            Throw.If.Null(stream, "stream");

            lock (this.c.SyncRoot)
            {
                this.Close();

                this.options = options ?? new VncServerSessionOptions();
                this.c.Stream = stream;

                this.threadMain = new Thread(this.ThreadMain);
                this.threadMain.IsBackground = true;
                this.threadMain.Start();
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Starts a session with a VNC client.
 /// </summary>
 /// <param name="stream">The stream containing the connection.</param>
 /// <param name="options">Session options, if any.</param>
 public void Connect(Stream stream, VncServerSessionOptions options = null)
 {
     this.Connect(stream, options, true);
 }