public void ConnectTcpArgumentsTest() { VncClient client = new VncClient(); Assert.Throws <ArgumentNullException>(() => client.Connect(null, 5900, null)); Assert.Throws <ArgumentOutOfRangeException>(() => client.Connect("localhost", -1, null)); }
public override Server creack(String ip, int port, String username, String password, int timeOut) { VncClient vc = null; Server server = new Server(); try { vc = new VncClient(); Boolean result = vc.Connect(ip, 0, port); if (result) { server.isSuccess = vc.Authenticate(password); } } catch (Exception e) { throw e; } finally { if (vc != null) { vc.Disconnect(); } } return(server); }
private void TestConfig(MainWindowViewModel vm) { using (var client = new VncClient(config.BitsPerPixel, config.Depth)) { try { client.Connect(vm.Host, vm.Port); client.Authenticate(new VncAuthenticator(vm.Password)); client.Disconnect(); MessageBox.Show("OK.", "Config", MessageBoxButton.OK, MessageBoxImage.Information); } catch (SocketException e) { MessageBox.Show(e.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error); } catch (VncSecurityException e) { MessageBox.Show(e.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception e) { MessageBox.Show($"{e.Message}\r\n{e.StackTrace}", Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error); } } }
public MouseControlForm(string ipOrHostname, int width, int height) { InitializeComponent(); DoubleBuffered = true; vncClient = new VncClient(ipOrHostname, Constants.VNC_PORT) { ReceiveBufferSize = Constants.IMAGE_SIZE, ReceiveTimeout = 1000 }; ClientSize = new Size(width, height); vncClient.SetNewDataArriveEventHandler(DataArrivedHandler); Task.Factory.StartNew(() => { while (working) { try { vncClient.Send(VncCommand.GetScreen); Thread.Sleep(Constants.SCREEN_WAIT_TIME); } catch (SocketException) { working = false; } } }); }
/// <summary> /// Initializes a new instance of the <see cref="VncControl"/>. /// </summary> public VncControl() { AllowInput = true; AllowRemoteCursor = true; Client = new VncClient(); InitializeComponent(); }
/// <summary> /// Decrypts the password (if any) associated with the connection (<see cref="BaseConnection.InheritedPassword"/> and provides it to /// <see cref="_vncConnection"/> for use in the connection process. /// </summary> /// <returns>The decrypted contents, if any, of <see cref="BaseConnection.InheritedPassword"/>.</returns> private char[] GetPassword(VncClient client) { string password = null; SecureString inheritedPassword = Connection.InheritedPassword; if (inheritedPassword != null && inheritedPassword.Length > 0) { password = Marshal.PtrToStringAnsi(Marshal.SecureStringToGlobalAllocAnsi(inheritedPassword)); } return(password.ToCharArray()); }
public ConnectionManager(InteractiveAuthenticationHandler?interactiveAuthenticationHandler = null) { _interactiveAuthenticationHandler = interactiveAuthenticationHandler ?? Locator.Current.GetService <InteractiveAuthenticationHandler>() ?? throw new ArgumentNullException(nameof(interactiveAuthenticationHandler)); // Create and populate default logger factory for logging to Avalonia logging sinks var loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(new AvaloniaLoggerProvider()); _vncClient = new VncClient(loggerFactory); }
private void Send(string message, DataArrivedEventHandler vncClientDataArrived = null) { try { var vncClient = new VncClient(cb_Computer.Text, Constants.VNC_PORT); vncClient.SetNewDataArriveEventHandler(vncClientDataArrived); vncClient.Send(message); } catch (Exception ex) { ErrorBox.Show("MainForm.Send", ex); } }
public void Test() { using (var vncClient = new VncClient()) { vncClient.Connect(Address, 5900, new VncClientConnectOptions { OnDemandMode = true, PasswordRequiredCallback = c => "100".ToArray() }); var width = 200; var height = 300; var copy = vncClient.GetFramebuffer(100, 100, width, height); var bitmap = this.CreateBitmap(copy, width, height); bitmap.Save(@"C:\TestOutput\Test.bmp", ImageFormat.Bmp); Assert.AreNotEqual(Color.Black.ToArgb(), bitmap.GetPixel(10, 10).ToArgb()); } }
private void VncClient_DataArrived(object sender, DataArrivedEventArgs e) { var message = VncClient.GetMessage(sender, e); if (message.StartsWith(VncCommand.ScreenSize)) { var data = message.Split(VncCommand.Separator, 'x'); var width = Convert.ToInt32(data[1]); var height = Convert.ToInt32(data[2]); cb_Computer.Invoke((MethodInvoker) delegate { var mcf = new MouseControlForm(cb_Computer.Text, width, height); mcf.Show(); }); } }
/// <summary> /// Connect to a VNC Host and determine whether or not the server requires a password. /// </summary> /// <param name="host">The IP Address or Host Name of the VNC Host.</param> /// <param name="display">The Display number (used on Unix hosts).</param> /// <param name="viewOnly">Determines whether mouse and keyboard events will be sent to the host.</param> /// <param name="scaled">Determines whether to use desktop scaling or leave it normal and clip.</param> /// <exception cref="System.ArgumentNullException">Thrown if host is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if display is negative.</exception> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already Connected. See <see cref="VncSharp.RemoteDesktop.IsConnected" />.</exception> public void Connect(string host, int display, bool viewOnly, bool scaled) { // TODO: Should this be done asynchronously so as not to block the UI? Since an event // indicates the end of the connection, maybe that would be a better design. InsureConnection(false); if (host == null) { throw new ArgumentNullException("host"); } if (display < 0) { throw new ArgumentOutOfRangeException("display", display, "Display number must be a positive integer."); } // Start protocol-level handling and determine whether a password is needed vnc = new VncClient(); vnc.ConnectionLost += VncClientConnectionLost; vnc.ServerCutText += VncServerCutText; passwordPending = vnc.Connect(host, display, VncPort, viewOnly); SetScalingMode(scaled); if (passwordPending) { // Server needs a password, so call which ever method is refered to by the GetPassword delegate. string password = GetPassword(); if (password == null) { // No password could be obtained (e.g., user clicked Cancel), so stop connecting return; } else { Authenticate(password); } } else { // No password needed, so go ahead and Initialize here Initialize(); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { var config = await ReadConfigAsync(); _VncClient = new VncClient(config.BitsPerPixel, config.Depth); _VncClient.Connect(config.Host, config.Port); var auth = new VncAuthenticator(config.Password); _VncClient.Authenticate(auth); _VncClient.Initialize(); _VncImage = new WriteableBitmap(_VncClient.Framebuffer.Width, _VncClient.Framebuffer.Height); VncImage.Source = _VncImage; _VncClient.OnFramebufferUpdate += _VncClient_OnFramebufferUpdate; _VncClient.ReceiveUpdates(); }
private async void _VncClient_OnFramebufferUpdate(VncClient sender, FramebufferUpdateEventArgs e) { Stream stream = null; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { stream = _VncImage.PixelBuffer.AsStream(); }); foreach (var item in e.Rectangles) { UpdateRectangle(stream, e.Framebuffer, item); } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { stream?.Dispose(); _VncImage.Invalidate(); }); }
/// <summary> /// Connect to a VNC Host and determine whether or not the server requires a password. /// </summary> /// <exception cref="System.ArgumentNullException">Thrown if host is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if display is negative.</exception> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already Connected. /// See <see cref="IsConnected" />.</exception> public void Connect() { // TODO: Should this be done asynchronously so as not to block the UI? Since an event // indicates the end of the connection, maybe that would be a better design. InsureConnection(false); if (host == null) { throw new ArgumentNullException(nameof(host)); } if (display < 0) { throw new ArgumentOutOfRangeException(nameof(display), display, "Display number must be a positive integer."); } // Start protocol-level handling and determine whether a password is needed vnc = new VncClient(); vnc.ConnectionLost += VncClientConnectionLost; vnc.ServerCutText += VncServerCutText; vnc.ViewOnly = viewOnlyMode; passwordPending = vnc.Connect(host, display, VncPort, viewOnlyMode); // SetScalingMode(scaled); if (passwordPending) { if (password != null) { Authenticate(password); } } else { // No password needed, so go ahead and Initialize here Initialize(); } }
private void vncControl1_Load(object sender, EventArgs e) { VncClient vnc = new VncClient(); }
public VncDesktopTransformPolicy(VncClient vnc, VncDesktop remoteDesktop) { this.vnc = vnc; this.remoteDesktop = remoteDesktop; }
public VncScaledDesktopPolicy(VncClient vnc, VncDesktop remoteDesktop) : base(vnc, remoteDesktop) { }
public bool Connect(VncConfig a_config) { // Connect Vnc m_client?.Dispose(); m_client = new VncClient(a_config); m_client.DisconnectedEvent += (s, e) => { if (InvokeRequired) { Invoke((MethodInvoker) delegate { DisconnectedEvent?.Invoke(s, e); }); } else { DisconnectedEvent?.Invoke(s, e); } }; bool retVal = m_client.ConnectVnc(); if (!retVal) { m_client.Dispose(); m_client = null; return(false); } // Draw the whole for the first time. m_needsRedraw = true; // Initialize zoom ratio for mouseEvent. m_xZoom = new Fraction(this.Width, m_client.ServerInitBody.FramebufferWidth, 10); m_yZoom = new Fraction(this.Height, m_client.ServerInitBody.FramebufferHeight, 10); // Create new image to draw OpenCv Mat. m_image?.Dispose(); m_image = new Bitmap(m_client.ServerInitBody.FramebufferWidth, m_client.ServerInitBody.FramebufferHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // Create read thread m_cancelTokenSource?.Dispose(); m_cancelTokenSource = new CancellationTokenSource(); var token = m_cancelTokenSource.Token; m_readTask?.Dispose(); m_readTask = Task.Factory.StartNew(() => { while (true) { if (m_client != null && m_client.Connected) { // If Read is failed, it returns null. var body = m_client.ReadServerMessage(); if (body == null) { // Disconnect m_client?.DisconnectVnc(); // Execute to draw this control black. // Without this, the screen will not be updated and the VNC image will remain. NativeMethods.InvalidateRect(m_handle, (IntPtr)0, false); return; } if (body.MessageType == VncEnum.MessageTypeServerToClient.FramebufferUpdate) { NativeMethods.InvalidateRect(m_handle, (IntPtr)0, false); lock (m_client.CanvasLock) { m_encodeList.Add(body.EncodeList); } } if (token.IsCancellationRequested) { return; } } } }, m_cancelTokenSource.Token); return(retVal); }
public void ConnectStreamArgumentsTest() { VncClient client = new VncClient(); Assert.Throws <ArgumentNullException>(() => client.Connect(null, null)); }
public void SendLocalClipboardChangeNullTest() { VncClient client = new VncClient(); Assert.Throws <ArgumentNullException>(() => client.SendLocalClipboardChange(null)); }