Skip to content

Commit

Permalink
Add documentation and erro handling to isototest
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteOtter committed Jul 19, 2024
1 parent 3318d99 commit 3d40e13
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions isototest/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
use tokio::{self, net::TcpStream};
use vnc::{PixelFormat, VncClient, VncConnector, VncError};

/// Create a new VNC client.
///
/// During the connection process the connection to the VNC server is
/// tested.
///
/// # Parameters
///
/// * target_ip: `String` - The IP and port of the VNC target server. (e.g `172.0.0.1:5900`)
/// * psw: `String` - The password used for authenticating with the server. (If the server
/// does not use authentication, this is irrelevant.)
///
/// # Returns
///
/// * vnc: `Ok(VncClient)` - A new instance of a `vnc-rs` `VncClient`.
/// * `Err(VncError)` - A `VncError` type, depending on the cause of failure.
///
/// # Panics
///
/// This function may panic, if the connection to the VNC server or the
/// configuration of the client fails.
pub async fn create_vnc_client(
target_ip: String,
psw: Option<String>,
mut psw: Option<String>,
) -> Result<VncClient, VncError> {
let tcp: TcpStream = TcpStream::connect(target_ip).await?;
if psw.is_none() {
psw = Some(String::new());
}

let tcp: TcpStream = match TcpStream::connect(target_ip).await {
Ok(tcp) => tcp,
Err(e) => {
let err = VncError::IoError(e);
return Err(err);
}
};

let vnc: VncClient = VncConnector::new(tcp)
.set_auth_method(async move { Ok(psw.unwrap()) })
.add_encoding(vnc::VncEncoding::Tight)
Expand Down

0 comments on commit 3d40e13

Please sign in to comment.