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 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(); } }