Ejemplo n.º 1
0
        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();
            }
        }