Connect() public method

Attempt to connectFromClient to a remote VNC Host.
public Connect ( string host, int port ) : void
host string The IP Address or Host Name of the VNC Host.
port int The Port number on which to connectFromClient. Usually this will be 5900, except in the case that the VNC Host is running on a different Display, in which case the Display number should be added to 5900 to determine the correct port.
return void
示例#1
0
        /// <summary>
        /// Main Function for Connect Process.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="display"></param>
        /// <param name="port"></param>
        /// <param name="viewOnly"></param>
        /// <param name="connectFromClient">Set true if connect from client to server. Set false if wait for a connection from server.</param>
        /// <returns></returns>
        private bool ConnectCore(string host, int display, ref int port, bool viewOnly, bool connectFromClient)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            // If a diplay number is specified (used to connectFromClient 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
            {
                if (connectFromClient)
                {
                    rfb.Connect(host, port);
                    return(DoHandShake());
                }
                else
                {
                    rfb.Listen(host, port);
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw new VncProtocolException("Unable to connect to the server. Error was: " + e.Message, e);
            }
        }
示例#2
0
        /// <summary>
        /// Main Function for Connect Process.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="display"></param>
        /// <param name="port"></param>
        /// <param name="viewOnly"></param>
        /// <param name="connectFromClient">Set true if connect from client to server. Set false if wait for a connection from server.</param>
        /// <returns></returns>
        private bool ConnectCore(string host, int display, ref int port, bool viewOnly, bool connectFromClient)
        {
            if (host == null) throw new ArgumentNullException("host");

            // If a diplay number is specified (used to connectFromClient 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
            {
                if (connectFromClient)
                {
                    rfb.Connect(host, port);
                    return DoHandShake();
                }
                else
                {
                    rfb.Listen(host, port);
                    return true;
                }                
            }
            catch (Exception e)
            {
                throw new VncProtocolException("Unable to connect to the server. Error was: " + e.Message, e);
            }
        }