/// Connects to the given eterm server.
///
/// ``` no_run
/// eterm::Client::new("127.0.0.1:8580".to_owned());
/// ```
Connects to the given eterm server.
Connects to the given eterm server .
pub fn new(addr: String) -> Self {
        let alive = Arc::new(AtomicBool::new(true));
        let connected = Arc::new(AtomicBool::new(false));
        let mut bandwidth_history = Arc::new(Mutex::new(History::new(0..200, 2.0)));
        let mut frame_size_history = Arc::new(Mutex::new(History::new(1..100, 0.5)));
        let (outgoing_msg_tx, mut outgoing_msg_rx) = mpsc::channel();
        let (mut incoming_msg_tx, incoming_msg_rx) = mpsc::channel();
        let client = Self {
            addr: addr.clone(),
            connected: connected.clone(),
            alive: alive.clone(),
            outgoing_msg_tx,
            incoming_msg_rx,
            font_definitions: Default::default(),
            fonts: None,
            latest_frame: Default::default(),
            bandwidth_history: bandwidth_history.clone(),
            frame_size_history: frame_size_history.clone(),
            latency_history: History::new(1..100, 1.0),
            frame_history: History::new(2..100, 1.0),
        };
        std::thread::spawn(move || {
            tracing::info!("Connecting to {}…", addr);
            while alive.load(SeqCst) {
                match std::net::TcpStream::connect(&addr) {
                    Ok(tcp_stream) => {
                        tracing::info!("Connected!");
                        connected.store(true, SeqCst);
                        if let Err(err) = run(
                            tcp_stream,
                            &mut outgoing_msg_rx,
                            &mut incoming_msg_tx,
                            &mut bandwidth_history,
                            &mut frame_size_history,
                        ) {
                            tracing::info!(
                                "Connection lost: {}",
                                crate::error_display_chain(err.as_ref())
                            );
                        } else {
                            tracing::info!("Connection closed.",);
                        }
                        connected.store(false, SeqCst);
                    }
                    Err(err) => {
                        tracing::debug!("Failed to connect to {}: {}", addr, err);
                        std::thread::sleep(std::time::Duration::from_secs(1));
                    }
                }
            }
        });
        client
    }
pub fn new ( addr : String ) -> Self { let alive = Arc :: new ( AtomicBool :: new ( true ) ) ; let connected = Arc :: new ( AtomicBool :: new ( false ) ) ; let mut bandwidth_history = Arc :: new ( Mutex :: new ( History :: new ( 0 .. 200 , 2.0 ) ) ) ; let mut frame_size_history = Arc :: new ( Mutex :: new ( History :: new ( 1 .. 100 , 0.5 ) ) ) ; let ( outgoing_msg_tx , mut outgoing_msg_rx ) = mpsc :: channel ( ) ; let ( mut incoming_msg_tx , incoming_msg_rx ) = mpsc :: channel ( ) ; let client = Self { addr : addr . clone ( ) , connected : connected . clone ( ) , alive : alive . clone ( ) , outgoing_msg_tx , incoming_msg_rx , font_definitions : Default :: default ( ) , fonts : None , latest_frame : Default :: default ( ) , bandwidth_history : bandwidth_history . clone ( ) , frame_size_history : frame_size_history . clone ( ) , latency_history : History :: new ( 1 .. 100 , 1.0 ) , frame_history : History :: new ( 2 .. 100 , 1.0 ) , } ; std :: thread :: spawn ( move | | { tracing :: info ! ( " dr); while alive . load ( SeqCst ) { match std :: net :: TcpStream :: connect ( & addr ) { Ok ( tcp_stream ) => { tracing :: info ! ( " " ) ; connected . store ( true , SeqCst ) ; if let Err ( err ) = run ( tcp_stream , & mut outgoing_msg_rx , & mut incoming_msg_tx , & mut bandwidth_history , & mut frame_size_history , ) { tracing :: info ! ( " " crate error_display_chain ( err as_ref ( ) ) ) ; } else { tracing :: info ! ( " " ) ; } connected . store ( false , SeqCst ) ; } Err ( err ) => { tracing :: debug ! ( " " addr err ) ; std :: thread :: sleep ( std :: time :: Duration :: from_secs ( 1 ) ) ; } } } } ) ; client }
Connects to the given eterm server.
Connects to the given eterm server .
addr
String