Skip to main content

run_client

Function run_client 

Source
pub async fn run_client(args: Args) -> Result<()>
Expand description

Creates and runs a terminal sharing session

This is the main entry point for the client functionality. It performs the following steps:

  1. Server Validation: Verifies connectivity to the tunnel server
  2. Session Registration: Creates a new session with authentication settings
  3. PTY Creation: Spawns a pseudo-terminal with the user’s shell
  4. WebSocket Connection: Establishes connection to tunnel server
  5. I/O Forwarding: Bidirectional data flow between terminal and web clients
  6. Event Handling: Manages terminal resizing, user input, and process lifecycle

§Arguments

  • args - Configuration including server addresses, passwords, and permissions

§Returns

  • Result<()> - Success or error result

§Example

use tshare::client::{Args, run_client};

let args = Args {
    tunnel_host: "localhost".to_string(),
    tunnel_port: 8385,
    web_host: "localhost".to_string(),
    web_port: 8386,
    owner_pass: Some("secret123".to_string()),
    guest_pass: None,
    guest_readonly: false,
};

run_client(args).await?;

§Behavior

The function will:

  • Display a shareable web link after successful session creation
  • Enable raw terminal mode for real-time character input
  • Forward all terminal I/O to connected web viewers
  • Handle terminal resize events from web clients
  • Clean up resources and exit when the terminal session ends

§Panics

Will panic if:

  • The tunnel server is unreachable
  • The tunnel server returns unexpected responses
  • Critical initialization steps fail