[][src]Type Definition daemon_engine::tcp::TcpConnection

type TcpConnection<C> = Connection<TcpStream, C>;

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();

Methods

impl<C> TcpConnection<C> where
    C: Encoder + Decoder + Clone + Send + 'static,
    <C as Decoder>::Item: Send,
    <C as Decoder>::Error: Send + Debug
[src]

pub fn new(
    addr: &SocketAddr,
    codec: C
) -> impl Future<Item = Connection<TcpStream, C>, Error = Error>
[src]

Create a new client connected to the provided TCP socket address

pub fn close(self)[src]