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§
source§impl<C> TcpConnection<C>where
C: Encoder + Decoder + Default + Send + 'static,
<C as Decoder>::Item: Send,
<C as Decoder>::Error: Send + Debug,
impl<C> TcpConnection<C>where
C: Encoder + Decoder + Default + Send + 'static,
<C as Decoder>::Item: Send,
<C as Decoder>::Error: Send + Debug,
sourcepub fn new(addr: &SocketAddr) -> Result<Connection<TcpStream, C>, Error>
pub fn new(addr: &SocketAddr) -> Result<Connection<TcpStream, C>, Error>
Create a new client connected to the provided TCP socket address