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 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()); } }
/// <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(); }
/// <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(); } }
public void ConnectStreamArgumentsTest() { VncClient client = new VncClient(); Assert.Throws <ArgumentNullException>(() => client.Connect(null, null)); }