/// Creates a new client and performs initial Telnet options negotiation.
Creates a new client and performs initial Telnet options negotiation.
Creates a new client and performs initial Telnet options negotiation .
pub fn new(port: u16) -> Self {
        let (req_tx, mut req_rx) = mpsc::channel(16);
        let (event_tx, event_rx) = mpsc::channel(16);
        std::thread::spawn(move || {
            // set up connection
            let mut connection =
                Telnet::connect(("127.0.0.1", port), 1024).expect("failed to connect to ReMUD");
            match connection
                .read_timeout(Duration::from_secs(10))
                .expect("did not receive DO TTYPE")
            {
                TelnetEvent::Negotiation(NegotiationAction::Do, TelnetOption::TTYPE) => {
                    connection
                        .negotiate(&NegotiationAction::Wont, TelnetOption::TTYPE)
                        .unwrap();
                }
                other => panic!(
                    "received unexpected message waiting for DO TTYPE: {:?}",
                    other
                ),
            }
            while let Some(req) = req_rx.blocking_recv() {
                match req {
                    TelnetRequest::Recv => {
                        let event = connection.read_timeout(Duration::from_secs(10)).unwrap();
                        event_tx.blocking_send(event).unwrap();
                    }
                    TelnetRequest::Send(message) => {
                        connection.write(message.as_bytes()).unwrap();
                    }
                }
            }
        });
        TelnetConnection {
            buffer: String::new(),
            output: VecDeque::new(),
            req_tx,
            event_rx,
        }
    }
pub fn new ( port : u16 ) -> Self { let ( req_tx , mut req_rx ) = mpsc :: channel ( 16 ) ; let ( event_tx , event_rx ) = mpsc :: channel ( 16 ) ; std :: thread :: spawn ( move | | { // set up connection let mut connection = Telnet :: connect ( ( " " , port ) , 1024 ) . expect ( " " ) ; match connection . read_timeout ( Duration :: from_secs ( 10 ) ) . expect ( " " ) { TelnetEvent :: Negotiation ( NegotiationAction :: Do , TelnetOption :: TTYPE ) => { connection . negotiate ( & NegotiationAction :: Wont , TelnetOption :: TTYPE ) . unwrap ( ) ; } other => panic ! ( " " other ) , } while let Some ( req ) = req_rx . blocking_recv ( ) { match req { TelnetRequest :: Recv => { let event = connection . read_timeout ( Duration :: from_secs ( 10 ) ) . unwrap ( ) ; event_tx . blocking_send ( event ) . unwrap ( ) ; } TelnetRequest :: Send ( message ) => { connection . write ( message . as_bytes ( ) ) . unwrap ( ) ; } } } } ) ; TelnetConnection { buffer : String :: new ( ) , output : VecDeque :: new ( ) , req_tx , event_rx , } }
Creates a new client and performs initial Telnet options negotiation.
Creates a new client and performs initial Telnet options negotiation .
port
u16