the point of this crate is to provide networking support between peers on MAC, Linux, and Windows it will also act as the artifice server
future implementations include async read/write, as well as async compression
it would be better to use a management crate but these example would technically work
```rust use networking::{ArtificeConfig, ArtificeHost, ArtificePeer}; use std::fs::File; use std::io::Read; fn main() { let mut configfile = File::open("host.json").unwrap(); let mut confvec = String::new(); configfile.readtostring(&mut confvec).unwrap(); let config: ArtificeConfig = serdejson::fromstr(&confvec).unwrap(); let mut file = File::open("peer.json").unwrap(); let mut invec = Vec::new(); file.readtoend(&mut invec).unwrap(); let string = String::fromutf8(invec).unwrap(); // println!("invec: {}", invec); let peer: ArtificePeer = serdejson::fromstr(&string).unwrap(); let host = ArtificeHost::clientonly(&config); let mut stream = host.connect(peer).unwrap(); let mut buffer = Vec::new(); println!("about to read from sream"); println!( "got {} bytes from server", stream.recv(&mut buffer).unwrap() ); println!("read from stream"); let string = String::fromutf8(buffer).unwrap(); println!("got message: {} from server", string); //stream.write(&buffer).unwrap(); }
```
```rust use networking::{ArtificeConfig, ArtificeHost, ArtificePeer}; use std::fs::File; use std::io::{Read}; fn main() { let mut configfile = File::open("host.json").unwrap(); let mut confvec = String::new(); configfile.readtostring(&mut confvec).unwrap(); let config: ArtificeConfig = serdejson::fromstr(&confvec).unwrap(); let host = ArtificeHost::fromhostdata(&config).unwrap(); let mut file = File::open("peer.json").unwrap(); let mut invec = String::new(); file.readtostring(&mut invec).unwrap(); let peer: ArtificePeer = serdejson::fromstr(&invec).unwrap(); for netstream in host { let mut stream = netstream.unwrap(); println!("about to write to stream"); stream .send(&"hello world".tostring().into_bytes()) .unwrap(); // do something with the stream example: if *stream.peer() == peer { // correct peer } } }
```