Struct SyncStream

Source
pub struct SyncStream { /* private fields */ }
Expand description

the TcpStream version of the artifice network, implements encryption automatically in its implementation of std::io::Write, and std::io::Read

Implementations§

Source§

impl SyncStream

Source

pub fn recv(&mut self, outbuf: &mut Vec<u8>) -> Result<usize, NetworkError>

implented in place of std::io::Read, because reading to empty vec fails

Examples found in repository?
examples/client.rs (line 18)
4fn main() {
5    // this function is for testing only
6    let (mut peer, config) = test_config();
7    peer.set_socket_addr(SocketAddr::new(
8        IpAddr::V4(Ipv4Addr::new(10, 0, 0, 81)),
9        6464,
10    ));
11    let host = SyncHost::client_only(&config).unwrap();
12    let mut stream = host.connect(peer).unwrap();
13    println!("connected");
14    let mut buffer = Vec::new();
15    println!("about to read from sream");
16    println!(
17        "got {} bytes from server",
18        stream.recv(&mut buffer).unwrap()
19    );
20    println!("read from stream");
21    let string = String::from_utf8(buffer).unwrap();
22    println!("got message: {} from server", string);
23}
Source

pub fn send(&mut self, buffer: &[u8]) -> Result<usize, NetworkError>

send data to the peer

Examples found in repository?
examples/listen.rs (line 9)
3fn main() {
4    let (peer, config) = test_config();
5    let host = SyncHost::from_host_data(&config).unwrap();
6    for netstream in host {
7        println!("new connection");
8        let mut stream = netstream.unwrap().verify(&peer).unwrap();
9        stream.send(&random_string(55555).into_bytes()).unwrap();
10        break;
11    }
12}

Trait Implementations§

Source§

impl Debug for SyncStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SyncDataStream for SyncStream

Source§

type NetStream = TcpStream

Source§

type Error = NetworkError

Source§

fn new( stream: Self::NetStream, header: StreamHeader, remote_addr: SocketAddr, ) -> Result<Self, Self::Error>

Source§

fn socket_addr(&self) -> SocketAddr

Source§

fn header(&self) -> &StreamHeader

Source§

fn addr(&self) -> IpAddr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V