/// <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; }
public VncDefaultInputPolicy(RfbProtocol rfb) { Debug.Assert(rfb != null); this.rfb = rfb; }
public VncViewInputPolicy(RfbProtocol rfb) { Debug.Assert(rfb != null); }
/// <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(2000); // this number is arbitrary, just so that it doesn't block forever.... rfb.Close(); rfb = null; }
/// <summary> /// Wait for a connection from VNC Server. /// </summary> /// <param name="host"></param> /// <param name="port"></param> /// <param name="viewOnly"></param> public void Listen(string host, int port, bool viewOnly) { if (host == null) throw new ArgumentNullException("host"); 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.RfbConnectedFromServer += new EventHandler(ConnectedFromServerEventHandler); rfb.FailedToListen += new EventHandler(FailedToListenHandler); rfb.Listen(host, port); } catch (Exception) { if (ConnectionLost != null) { ConnectionLost(this, EventArgs.Empty); } } }
/// <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); } }