Type Definition daemon_engine::tcp::TcpConnection

source ·
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).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();

Implementations§

Create a new client connected to the provided TCP socket address