title: How to write using tokio Framed LinesCodec?
body: <p>The following code reads from my server successfully, however I cannot seem to get the correct syntax or semantics to write back to the server when a particular line command is recognized. Do I need to create a <code>FramedWriter</code>? Most examples I have found split the socket but that seems overkill I expect the codec to be able to handle the bi-directional io by providing some async write method.</p>
  <pre class="lang-toml prettyprint-override"><code># Cargo.toml
  [dependencies]
  tokio = { version = &quot;0.3&quot;, features = [&quot;full&quot;] }
  tokio-util = { version = &quot;0.4&quot;, features = [&quot;codec&quot;] }
  </code></pre>
  <pre><code>//! main.rs
  use tokio::net::{ TcpStream };
  use tokio_util::codec::{ Framed, LinesCodec };
  use tokio::stream::StreamExt;
  use std::error::Error;
  use std::net::{IpAddr, Ipv4Addr, SocketAddr};
  
  #[tokio::main]
  async fn main() -&gt; Result&lt;(), Box&lt;dyn Error&gt;&gt; {
      let saddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081); 
      let conn = TcpStream::connect(saddr).await?;
  
      let mut server = Framed::new(conn, LinesCodec::new_with_max_length(1024));
  
      while let Some(Ok(line)) = server.next().await {
          match line.as_str() {
              &quot;READY&quot; =&gt; println!(&quot;Want to write a line to the stream&quot;),
              _ =&gt; println!(&quot;{}&quot;, line),
          }
      }
  
      Ok({})
  }
  </code></pre>