public EncodedRectangle Build(QuadNode node, VncHost.Encoding encoding) { int[] pixels = node.NodeData; EncodedRectangle e; switch (encoding) { case VncHost.Encoding.RawEncoding: e = new RawRectangle(rfb, framebuffer, pixels, node.Bounds); break; case VncHost.Encoding.CopyRectEncoding: e = new CopyRectRectangle(rfb, framebuffer, node.Bounds); break; case VncHost.Encoding.RreEncoding: e = new RreRectangle(rfb, framebuffer, pixels, node.Bounds); break; case VncHost.Encoding.CoRreEncoding: e = new CoRreRectangle(rfb, framebuffer, pixels, node.Bounds); break; case VncHost.Encoding.HextileEncoding: e = new HextileRectangle(rfb, framebuffer, pixels, node.Bounds); break; case VncHost.Encoding.ZrleEncoding: e = new ZrleRectangle(rfb, framebuffer, pixels, node.Bounds); break; case VncHost.Encoding.ZlibEncoding: e = new ZlibRectangle(rfb, framebuffer, pixels, node.Bounds); break; default: // Sanity check throw new Exception("Unsupported Encoding Format received: " + encoding + "."); } return e; }
/// <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(VncHost rfb, Framebuffer framebuffer) { Debug.Assert(rfb != null, "RfbProtocol object must be non-null"); Debug.Assert(framebuffer != null, "Framebuffer object must be non-null"); this.rfb = rfb; this.framebuffer = framebuffer; }
/// <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(VncHost 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 void Start() { if (string.IsNullOrEmpty(Name)) { throw new ArgumentNullException("Name", "The VNC Server Name cannot be empty."); } if (Port == 0) { throw new ArgumentNullException("Port", "The VNC Server port cannot be zero."); } if (ProxyPort == 0) { throw new ArgumentNullException("ProxyPort", "You must set a proxy port."); } new Thread(() => { Console.WriteLine("Started VNC Server at port: " + Port + " and proxy port at: " + ProxyPort); proxy = new VncProxy(Path, ProxyPort, Port); proxy.StartWebsockify(); host = new VncHost(Port, Name, new ScreenHandler(new Rectangle(0, 0, ScreenSize().Width, ScreenSize().Height), true)); host.WriteProtocolVersion(); Console.WriteLine("Wrote Protocol Version"); host.ReadProtocolVersion(); Console.WriteLine("Read Protocol Version"); Console.WriteLine("Awaiting Authentication"); if (!host.WriteAuthentication(Password)) { Console.WriteLine("Authentication failed !"); Stop(); //Start(); } else { Console.WriteLine("Authentication successfull !"); var share = host.ReadClientInit(); Console.WriteLine("Share: " + share); Console.WriteLine("Server name: " + fb.DesktopName); host.WriteServerInit(fb); while (host.isRunning) { switch (host.ReadServerMessageType()) { case VncHost.ClientMessages.SetPixelFormat: Console.WriteLine("Read SetPixelFormat"); var f = host.ReadSetPixelFormat(fb.Width, fb.Height); if (f != null) { fb = f; } break; case VncHost.ClientMessages.ReadColorMapEntries: Console.WriteLine("Read ReadColorMapEntry"); host.ReadColorMapEntry(); break; case VncHost.ClientMessages.SetEncodings: Console.WriteLine("Read SetEncodings"); host.ReadSetEncodings(); break; case VncHost.ClientMessages.FramebufferUpdateRequest: Console.WriteLine("Read FrameBufferUpdateRequest"); host.ReadFrameBufferUpdateRequest(fb); break; case VncHost.ClientMessages.KeyEvent: Console.WriteLine("Read KeyEvent"); host.ReadKeyEvent(); break; case VncHost.ClientMessages.PointerEvent: Console.WriteLine("Read PointerEvent"); host.ReadPointerEvent(); break; case VncHost.ClientMessages.ClientCutText: Console.WriteLine("Read CutText"); host.ReadClientCutText(); break; } } if (!host.isRunning) { Console.WriteLine("Stopping Websockify"); } proxy.StopWebsockify(); //Start(); } }).Start(); }
public void Start() { if (String.IsNullOrEmpty(Name)) { throw new ArgumentNullException("Name", "The VNC Server Name cannot be empty."); } if (Port == 0) { throw new ArgumentNullException("Port", "The VNC Server port cannot be zero."); } Console.WriteLine("Started VNC Server at port: " + Port); host = new VncHost(Port, Name); host.Start(); host.WriteProtocolVersion(); Console.WriteLine("Wrote Protocol Version"); host.ReadProtocolVersion(); Console.WriteLine("Read Protocol Version"); Console.WriteLine("Awaiting Authentication"); if (!host.WriteAuthentication(Password)) { Console.WriteLine("Authentication failed !"); host.Close(); //Start(); } else { Console.WriteLine("Authentication successfull !"); bool share = host.ReadClientInit(); Console.WriteLine("Share: " + share); Console.WriteLine("Server name: " + fb.DesktopName); host.WriteServerInit(fb); while ((host.isRunning)) { switch (host.ReadServerMessageType()) { case VncHost.ClientMessages.SetPixelFormat: Console.WriteLine("Read SetPixelFormat"); Framebuffer f = host.ReadSetPixelFormat(fb.Width, fb.Height); if (f != null) { fb = f; } break; case VncHost.ClientMessages.ReadColorMapEntries: Console.WriteLine("Read ReadColorMapEntry"); host.ReadColorMapEntry(); break; case VncHost.ClientMessages.SetEncodings: Console.WriteLine("Read SetEncodings"); host.ReadSetEncodings(); break; case VncHost.ClientMessages.FramebufferUpdateRequest: Console.WriteLine("Read FrameBufferUpdateRequest"); host.ReadFrameBufferUpdateRequest(fb); break; case VncHost.ClientMessages.KeyEvent: Console.WriteLine("Read KeyEvent"); host.ReadKeyEvent(); break; case VncHost.ClientMessages.PointerEvent: Console.WriteLine("Read PointerEvent"); host.ReadPointerEvent(); break; case VncHost.ClientMessages.ClientCutText: Console.WriteLine("Read CutText"); host.ReadClientCutText(); break; } } //if (!host.isRunning) //Start(); } }
public void Start() { if (String.IsNullOrEmpty(Name)) throw new ArgumentNullException("Name", "The VNC Server Name cannot be empty."); if (Port == 0) throw new ArgumentNullException("Port", "The VNC Server port cannot be zero."); Console.WriteLine("Started VNC Server at port: " + Port); host = new VncHost(Port, Name, new ScreenHandler(new Rectangle(0, 0, ScreenSize().Width, ScreenSize().Height), true)); host.WriteProtocolVersion(); Console.WriteLine("Wrote Protocol Version"); host.ReadProtocolVersion(); Console.WriteLine("Read Protocol Version"); Console.WriteLine("Awaiting Authentication"); if (!host.WriteAuthentication(Password)) { Console.WriteLine("Authentication failed !"); host.Close(); //Start(); } else { Console.WriteLine("Authentication successfull !"); bool share = host.ReadClientInit(); Console.WriteLine("Share: " + share); Console.WriteLine("Server name: " + fb.DesktopName); host.WriteServerInit(fb); while ((host.isRunning)) { switch (host.ReadServerMessageType()) { case VncHost.ClientMessages.SetPixelFormat: Console.WriteLine("Read SetPixelFormat"); Framebuffer f = host.ReadSetPixelFormat(fb.Width, fb.Height); if (f != null) fb = f; break; case VncHost.ClientMessages.ReadColorMapEntries: Console.WriteLine("Read ReadColorMapEntry"); host.ReadColorMapEntry(); break; case VncHost.ClientMessages.SetEncodings: Console.WriteLine("Read SetEncodings"); host.ReadSetEncodings(); break; case VncHost.ClientMessages.FramebufferUpdateRequest: Console.WriteLine("Read FrameBufferUpdateRequest"); host.ReadFrameBufferUpdateRequest(fb); break; case VncHost.ClientMessages.KeyEvent: Console.WriteLine("Read KeyEvent"); host.ReadKeyEvent(); break; case VncHost.ClientMessages.PointerEvent: Console.WriteLine("Read PointerEvent"); host.ReadPointerEvent(); break; case VncHost.ClientMessages.ClientCutText: Console.WriteLine("Read CutText"); host.ReadClientCutText(); break; } } //if (!host.isRunning) //Start(); } }
/// <summary> /// Creates an object type derived from EncodedRectangle, based on the value of encoding. /// </summary> /// <param name="rectangle">A node object from the Screen Handler defining the bounds of the rectangle and the pixel data. IT SHOULD BE CONSIDERED LOCALLY AGAINST pixels param, not globally against the screen size</param> /// <param name="encoding">An Integer indicating the encoding type to be used for this rectangle. Used to determine the type of EncodedRectangle to create.</param> /// <returns></returns> public EncodedRectangle Build(Rectangle2 rectangle, VncHost.Encoding encoding) { Bitmap bmp = PixelGrabber.CreateScreenCapture(rectangle.ToRectangle()); int[] pixels = PixelGrabber.GrabPixels(bmp, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, bmp.PixelFormat); return Build(rectangle, pixels, encoding); }
public virtual void Start() { if (String.IsNullOrEmpty(Name)) { throw new ArgumentNullException("Name", "The VNC Server Name cannot be empty."); } if (Port == 0) { throw new ArgumentNullException("Port", "The VNC Server port cannot be zero."); } Console.WriteLine("Started VNC Server at port: " + Port); host = new VncHost(Port, Name, new ScreenHandler(new Rectangle(0, 0, ScreenSize().Width, ScreenSize().Height), true)); host.Start(this); host.WriteProtocolVersion(); Console.WriteLine("Wrote Protocol Version"); host.ReadProtocolVersion(); Console.WriteLine("Read Protocol Version"); Console.WriteLine("Awaiting Authentication"); if (!host.WriteAuthentication(Password)) { Console.WriteLine("Authentication failed !"); #if DEBUG //Start(); if (!Debugger.IsAttached) { host.Close(); return; } #else host.Close(); return; #endif } // else { Console.WriteLine("Authentication successfull !"); bool share = host.ReadClientInit(); Console.WriteLine("Share: " + share); Console.WriteLine("Server name: " + fb.DesktopName); host.WriteServerInit(fb); if (!host.isRunning) { Console.WriteLine("host.isRunning = false"); return; } while ((host.isRunning)) { switch (host.ReadServerMessageType()) { case VncHost.ClientMessages.Error: break; case VncHost.ClientMessages.SetPixelFormat: Console.WriteLine("Read SetPixelFormat"); Framebuffer f = host.ReadSetPixelFormat(fb.Width, fb.Height); if (f != null) { fb = f; } break; case VncHost.ClientMessages.ReadColorMapEntries: Console.WriteLine("Read ReadColorMapEntry"); host.ReadColorMapEntry(); break; case VncHost.ClientMessages.SetEncodings: Console.WriteLine("Read SetEncodings"); host.ReadSetEncodings(); break; case VncHost.ClientMessages.FramebufferUpdateRequest: Console.WriteLine("Read FrameBufferUpdateRequest"); host.ReadFrameBufferUpdateRequest(fb); break; case VncHost.ClientMessages.KeyEvent: Console.WriteLine("Read KeyEvent"); host.ReadKeyEvent(); break; case VncHost.ClientMessages.PointerEvent: Console.WriteLine("Read PointerEvent"); host.ReadPointerEvent(); break; case VncHost.ClientMessages.ClientCutText: Console.WriteLine("Read CutText"); host.ReadClientCutText(); break; } } //if (!host.isRunning) //Start(); } }