示例#1
0
        /// <summary>
        /// Stops sending requests for updates and disconnects from the remote host.  You must call Connect() again if you wish to re-establish a connection.
        /// </summary>
        public void Disconnect()
        {
            // Stop the worker thread.
            done.Set();

            // BUG FIX: [email protected] for UltraVNC disconnect issue
            // Request a tiny screen update to flush the blocking read
            try {
                rfb.WriteFramebufferUpdateRequest(0, 0, 1, 1, false);
            } catch {
                // this may not work, as Disconnect can get called in response to the
                // VncClient raising a ConnectionLost event (e.g., the remote host died).
            }

            worker.Join(3000);	// this number is arbitrary, just so that it doesn't block forever....

            rfb.Close();
            rfb = null;
        }
示例#2
0
		public VncDefaultInputPolicy(RfbProtocol rfb)
		{
			Debug.Assert(rfb != null);
			this.rfb = rfb;
		}
示例#3
0
        /// <summary>
        /// Connect to a VNC Host and determine which type of Authentication it uses. If the host uses Password Authentication, a call to Authenticate() will be required.
        /// </summary>
        /// <param name="host">The IP Address or Host Name of the VNC Host.</param>
        /// <param name="display">The Display number (used on Unix hosts).</param>
        /// <param name="port">The Port number used by the Host, usually 5900.</param>
        /// <param name="viewOnly">True if mouse/keyboard events are to be ignored.</param>
        /// <returns>Returns True if the VNC Host requires a Password to be sent after Connect() is called, otherwise False.</returns>
        public bool Connect(string host, int display, int port, bool viewOnly)
        {
            if (host == null) throw new ArgumentNullException("host");

            // If a diplay number is specified (used to connect to Unix servers)
            // it must be 0 or greater.  This gets added to the default port number
            // in order to determine where the server will be listening for connections.
            if (display < 0) throw new ArgumentOutOfRangeException("display", display, "Display number must be non-negative.");
            port += display;

            rfb = new RfbProtocol();

            if (viewOnly) {
                inputPolicy = new VncViewInputPolicy(rfb);
            } else {
                inputPolicy = new VncDefaultInputPolicy(rfb);
            }

            // Connect and determine version of server, and set client protocol version to match
            try {
                rfb.Connect(host, port);
                rfb.ReadProtocolVersion();
                rfb.WriteProtocolVersion();

                // Figure out which type of authentication the server uses
                byte[] types = rfb.ReadSecurityTypes();

                // Based on what the server sends back in the way of supported Security Types, one of
                // two things will need to be done: either the server will reject the connection (i.e., type = 0),
                // or a list of supported types will be sent, of which we need to choose and use one.
                if (types.Length > 0) {
                    if (types[0] == 0) {
                        // The server is not able (or willing) to accept the connection.
                        // A message follows indicating why the connection was dropped.
                        throw new VncProtocolException("Connection Failed. The server rejected the connection for the following reason: " + rfb.ReadSecurityFailureReason());
                    } else {
                        securityType = GetSupportedSecurityType(types);
                        Debug.Assert(securityType > 0, "Unknown Security Type(s)", "The server sent one or more unknown Security Types.");

                        rfb.WriteSecurityType(securityType);

                        // Protocol 3.8 states that a SecurityResult is still sent when using NONE (see 6.2.1)
                        if (rfb.ServerVersion == 3.8f && securityType == 1) {
                            if (rfb.ReadSecurityResult() > 0) {
                                // For some reason, the server is not accepting the connection.  Get the
                                // reason and throw an exception
                                throw new VncProtocolException("Unable to Connecto to the Server. The Server rejected the connection for the following reason: " + rfb.ReadSecurityFailureReason());
                            }
                        }

                        return (securityType > 1) ? true : false;
                    }
                } else {
                    // Something is wrong, since we should have gotten at least 1 Security Type
                    throw new VncProtocolException("Protocol Error Connecting to Server. The Server didn't send any Security Types during the initial handshake.");
                }
            } catch (Exception e) {
                throw new VncProtocolException("Unable to connect to the server. Error was: " + e.Message, e);
            }
        }
 public VncViewInputPolicy(RfbProtocol rfb)
 {
     Debug.Assert(rfb != null);
 }
示例#5
0
 public VncViewInputPolicy(RfbProtocol rfb)
 {
     Debug.Assert(rfb != null);
 }
示例#6
0
        /// <summary>
        /// Connect to a VNC Host and determine which type of Authentication it uses. If the host uses Password Authentication, a call to Authenticate() will be required.
        /// </summary>
        /// <param name="host">The IP Address or Host Name of the VNC Host.</param>
        /// <param name="display">The Display number (used on Unix hosts).</param>
        /// <param name="port">The Port number used by the Host, usually 5900.</param>
        /// <param name="viewOnly">True if mouse/keyboard events are to be ignored.</param>
        /// <returns>Returns True if the VNC Host requires a Password to be sent after Connect() is called, otherwise False.</returns>
        public bool Connect(string host, int display, int port, bool viewOnly)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            // If a diplay number is specified (used to connect to Unix servers)
            // it must be 0 or greater.  This gets added to the default port number
            // in order to determine where the server will be listening for connections.
            if (display < 0)
            {
                throw new ArgumentOutOfRangeException("display", display, "Display number must be non-negative.");
            }
            port += display;

            rfb = new RfbProtocol();

            if (viewOnly)
            {
                inputPolicy = new VncViewInputPolicy(rfb);
            }
            else
            {
                inputPolicy = new VncDefaultInputPolicy(rfb);
            }

            // Connect and determine version of server, and set client protocol version to match
            try {
                rfb.Connect(host, port);
                rfb.ReadProtocolVersion();

                // Handle possible repeater connection
                if (rfb.ServerVersion == 0.0)
                {
                    rfb.WriteProxyAddress();
                    // Now we are connected to the real server; read the protocol version of the
                    // server
                    rfb.ReadProtocolVersion();
                    // Resume normal handshake and protocol
                }

                rfb.WriteProtocolVersion();

                // Figure out which type of authentication the server uses
                byte[] types = rfb.ReadSecurityTypes();

                // Based on what the server sends back in the way of supported Security Types, one of
                // two things will need to be done: either the server will reject the connection (i.e., type = 0),
                // or a list of supported types will be sent, of which we need to choose and use one.
                if (types.Length > 0)
                {
                    if (types[0] == 0)
                    {
                        // The server is not able (or willing) to accept the connection.
                        // A message follows indicating why the connection was dropped.
                        throw new VncProtocolException("Connection Failed. The server rejected the connection for the following reason: " + rfb.ReadSecurityFailureReason());
                    }
                    else
                    {
                        securityType = GetSupportedSecurityType(types);
                        Debug.Assert(securityType > 0, "Unknown Security Type(s)", "The server sent one or more unknown Security Types.");

                        rfb.WriteSecurityType(securityType);

                        // Protocol 3.8 states that a SecurityResult is still sent when using NONE (see 6.2.1)
                        if (rfb.ServerVersion == 3.8f && securityType == 1)
                        {
                            if (rfb.ReadSecurityResult() > 0)
                            {
                                // For some reason, the server is not accepting the connection.  Get the
                                // reason and throw an exception
                                throw new VncProtocolException("Unable to Connecto to the Server. The Server rejected the connection for the following reason: " + rfb.ReadSecurityFailureReason());
                            }
                        }

                        return((securityType > 1) ? true : false);
                    }
                }
                else
                {
                    // Something is wrong, since we should have gotten at least 1 Security Type
                    throw new VncProtocolException("Protocol Error Connecting to Server. The Server didn't send any Security Types during the initial handshake.");
                }
            } catch (Exception e) {
                throw new VncProtocolException("Unable to connect to the server. Error was: " + e.Message, e);
            }
        }
示例#7
0
 public VncDefaultInputPolicy(RfbProtocol rfb)
 {
     Debug.Assert(rfb != null);
     this.rfb = rfb;
 }
		/// <summary>
		/// Creates an instance of the EncodedRectangleFactory using the connected RfbProtocol object and associated Framebuffer object.
		/// </summary>
		/// <param name="rfb">An RfbProtocol object that will be passed to any created EncodedRectangle objects.  Must be non-null, already initialized, and connected.</param>
		/// <param name="framebuffer">A Framebuffer object which will be used by any created EncodedRectangle objects in order to decode and draw rectangles locally.</param>
		public EncodedRectangleFactory(RfbProtocol rfb, Framebuffer framebuffer)
		{
			System.Diagnostics.Debug.Assert(rfb != null, "RfbProtocol object must be non-null");
			System.Diagnostics.Debug.Assert(framebuffer != null, "Framebuffer object must be non-null");
			
			this.rfb = rfb;
			this.framebuffer = framebuffer;
		}