pub type TcpConnection<C> = Connection<TcpStream, C>;Expand description
TcpConnection is a Connection implementation over TcpStream
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
extern crate tokio;
use tokio::prelude::*;
use tokio::{spawn, run};
#[macro_use]
extern crate serde_derive;
extern crate daemon_engine;
use daemon_engine::{TcpConnection, JsonCodec, DaemonError};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Request {}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Response {}
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8111);
let client = TcpConnection::<JsonCodec<Request, Response>>::new(&addr, JsonCodec::new()).wait().unwrap();
let (tx, rx) = client.split();
// Send data
tx.send(Request{}).wait().unwrap();
// Receive data
rx.map(|resp| -> Result<(), DaemonError> {
println!("Response: {:?}", resp);
Ok(())
}).wait().next();Aliased Type§
pub struct TcpConnection<C> { /* private fields */ }Implementations§
Source§impl<C> TcpConnection<C>
impl<C> TcpConnection<C>
Sourcepub fn new(
addr: &SocketAddr,
codec: C,
) -> impl Future<Item = Connection<TcpStream, C>, Error = Error>
pub fn new( addr: &SocketAddr, codec: C, ) -> impl Future<Item = Connection<TcpStream, C>, Error = Error>
Create a new client connected to the provided TCP socket address