| 100 | type ClientOutputProtocol = TCompactOutputProtocol<TFramedWriteTransport<WriteHalf<TTcpChannel>>>; |
| 101 | |
| 102 | fn new_client( |
| 103 | host: &str, |
| 104 | port: u16, |
| 105 | ) -> thrift::Result<CalculatorSyncClient<ClientInputProtocol, ClientOutputProtocol>> { |
| 106 | let mut c = TTcpChannel::new(); |
| 107 | |
| 108 | // open the underlying TCP stream |
| 109 | println!("connecting to tutorial server on {}:{}", host, port); |
| 110 | c.open(format!("{}:{}", host, port))?; |
| 111 | |
| 112 | // clone the TCP channel into two halves, one which |
| 113 | // we'll use for reading, the other for writing |
| 114 | let (i_chan, o_chan) = c.split()?; |
| 115 | |
| 116 | // wrap the raw sockets (slow) with a buffered transport of some kind |
| 117 | let i_tran = TFramedReadTransport::new(i_chan); |
| 118 | let o_tran = TFramedWriteTransport::new(o_chan); |
| 119 | |
| 120 | // now create the protocol implementations |
| 121 | let i_prot = TCompactInputProtocol::new(i_tran); |
| 122 | let o_prot = TCompactOutputProtocol::new(o_tran); |
| 123 | |
| 124 | // we're done! |
| 125 | Ok(CalculatorSyncClient::new(i_prot, o_prot)) |
| 126 | } |