/// <summary> /// Connects to a VNC server with the specified hostname and port. /// </summary> /// <param name="hostname">The name of the host to connect to.</param> /// <param name="port">The port to connect on. 5900 is the usual for VNC.</param> /// <param name="options">Connection options, if any. You can specify a password here.</param> public void Connect(string hostname, int port = 5900, VncClientConnectOptions options = null) { Throw.If.Null(hostname, "hostname").Negative(port, "port"); lock (_c.SyncRoot) { var client = new TcpClient(); try { client.Connect(hostname, port); } catch (Exception) { OnConnectionFailed(); throw; } try { Connect(client.GetStream(), options); } catch (Exception ex) { client.Close(); throw; } } }
/// <summary> /// Connects to a VNC server with the specified hostname and port. /// </summary> /// <param name="hostname">The name of the host to connect to.</param> /// <param name="port">The port to connect on. 5900 is the usual for VNC.</param> /// <param name="options">Connection options, if any. You can specify a password here.</param> public void Connect(string hostname, int port = 5900, VncClientConnectOptions options = null) { Throw.If.Null(hostname, "hostname").Negative(port, "port"); lock (this.c.SyncRoot) { var client = new TcpClient(); try { client.ConnectAsync(hostname, port).Wait(); } catch (Exception) { this.OnConnectionFailed(); throw; } try { this.Connect(client.GetStream(), options); } catch (Exception) { ((IDisposable)client).Dispose(); throw; } } }
/// <summary> /// Connects to a VNC server. /// </summary> /// <param name="stream">The stream containing the connection.</param> /// <param name="options">Connection options, if any. You can specify a password here.</param> public void Connect(Stream stream, VncClientConnectOptions options = null) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } lock (this.c.SyncRoot) { this.Close(); this.options = options ?? new VncClientConnectOptions(); this.c.Stream = stream; try { this.NegotiateVersion(); this.NegotiateSecurity(); this.NegotiateDesktop(); this.NegotiateEncodings(); this.InitFramebufferDecoder(); if (this.options.OnDemandMode) { this.IsConnected = true; } else { this.SendFramebufferUpdateRequest(false); this.threadMain = new Thread(this.ThreadMain); this.threadMain.IsBackground = true; this.threadMain.Start(); } } catch (IOException e) { this.OnConnectionFailed(); throw new VncException("IO error.", VncFailureReason.NetworkError, e); } catch (ObjectDisposedException e) { this.OnConnectionFailed(); throw new VncException("Connection closed.", VncFailureReason.NetworkError, e); } catch (SocketException e) { this.OnConnectionFailed(); throw new VncException("Connection failed.", VncFailureReason.NetworkError, e); } } }
/// <summary> /// Connects to a VNC server. /// </summary> /// <param name="stream">The stream containing the connection.</param> /// <param name="options">Connection options, if any. You can specify a password here.</param> public void Connect(Stream stream, VncClientConnectOptions options = null) { Throw.If.Null(stream, "stream"); lock (_c.SyncRoot) { Close(); _options = options ?? new VncClientConnectOptions(); _c.Stream = stream; try { NegotiateVersion(); NegotiateSecurity(); NegotiateDesktop(); NegotiateEncodings(); InitFramebufferDecoder(); SendFramebufferUpdateRequest(false); } catch (IOException e) { OnConnectionFailed(); throw new VncException("IO error.", VncFailureReason.NetworkError, e); } catch (ObjectDisposedException e) { OnConnectionFailed(); throw new VncException("Connection closed.", VncFailureReason.NetworkError, e); } catch (SocketException e) { OnConnectionFailed(); throw new VncException("Connection failed.", VncFailureReason.NetworkError, e); } _threadMain = new Thread(ThreadMain); _threadMain.IsBackground = true; _threadMain.Start(); } }
/// <summary> /// Connects to a VNC server with the specified hostname and port. /// </summary> /// <param name="hostname">The name of the host to connect to.</param> /// <param name="port">The port to connect on. 5900 is the usual for VNC.</param> /// <param name="options">Connection options, if any. You can specify a password here.</param> public void Connect(string hostname, int port = 5900, VncClientConnectOptions options = null) { if (hostname == null) { throw new ArgumentNullException(nameof(hostname)); } if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } lock (this.c.SyncRoot) { var client = new TcpClient(); try { client.ConnectAsync(hostname, port).Wait(); } catch (Exception) { this.OnConnectionFailed(); throw; } try { this.Connect(client.GetStream(), options); } catch (Exception) { ((IDisposable)client).Dispose(); throw; } } }
/// <summary> /// Initializes a new instance of the <see cref="PasswordRequiredEventArgs"/> class. /// </summary> /// <param name="options">The connection options.</param> public PasswordRequiredEventArgs(VncClientConnectOptions options) { Throw.If.Null(options, "options"); Options = options; }
/// <summary> /// Initializes a new instance of the <see cref="PasswordRequiredEventArgs"/> class. /// </summary> /// <param name="options">The connection options.</param> public PasswordRequiredEventArgs(VncClientConnectOptions options) { Throw.If.Null(options, "options"); Options = options; }
/// <summary> /// Connects to a VNC server. /// </summary> /// <param name="stream">The stream containing the connection.</param> /// <param name="options">Connection options, if any. You can specify a password here.</param> public void Connect(Stream stream, VncClientConnectOptions options = null) { Throw.If.Null(stream, "stream"); lock (this.c.SyncRoot) { this.Close(); this.options = options ?? new VncClientConnectOptions(); this.c.Stream = stream; try { this.NegotiateVersion(); this.NegotiateSecurity(); this.NegotiateDesktop(); this.NegotiateEncodings(); this.InitFramebufferDecoder(); this.SendFramebufferUpdateRequest(false); } catch (IOException e) { this.OnConnectionFailed(); throw new VncException("IO error.", VncFailureReason.NetworkError, e); } catch (ObjectDisposedException e) { this.OnConnectionFailed(); throw new VncException("Connection closed.", VncFailureReason.NetworkError, e); } catch (SocketException e) { this.OnConnectionFailed(); throw new VncException("Connection failed.", VncFailureReason.NetworkError, e); } this.threadMain = new Thread(this.ThreadMain); this.threadMain.IsBackground = true; this.threadMain.Start(); } }
/// <summary> /// Connects to a VNC server with the specified hostname and port. /// </summary> /// <param name="hostname">The name of the host to connect to.</param> /// <param name="port">The port to connect on. 5900 is the usual for VNC.</param> /// <param name="options">Connection options, if any. You can specify a password here.</param> public void Connect(string hostname, int port = 5900, VncClientConnectOptions options = null) { Throw.If.Null(hostname, "hostname").Negative(port, "port"); lock (this.c.SyncRoot) { var client = new TcpClient(); try { client.ConnectAsync(hostname, port).Wait(); } catch (Exception) { this.OnConnectionFailed(); throw; } try { this.Connect(client.GetStream(), options); } catch (Exception) { ((IDisposable)client).Dispose(); throw; } } }