Last active
April 11, 2016 08:46
-
-
Save tilpner/4904a7f7237d1bbb115a163a47e83bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(io)] | |
use std::io::{self, Read, Write}; | |
use std::net::TcpStream; | |
use std::process::exit; | |
use std::env; | |
fn main() { | |
let addr: u16 = 12345; | |
let args = env::args().skip(1).collect::<Vec<_>>().join(" "); | |
let mut stream = TcpStream::connect(("localhost", addr)).unwrap_or_else(|e| { | |
println!("Could not connect to port {}: {}", addr, e); | |
exit(1); | |
}); | |
// stream.write_all(b"Test\n").unwrap(); | |
stream.write_all(args.as_bytes()).unwrap(); | |
stream.flush().unwrap(); | |
for ch in stream.chars().filter_map(Result::ok) { | |
print!("{}", ch); | |
io::stdout().flush().expect("Unable to flush") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
use std::net::TcpListener; | |
use std::thread; | |
fn main() { | |
let listener = TcpListener::bind("127.0.0.1:12345").unwrap(); | |
for stream in listener.incoming() { | |
if let Ok(mut out) = stream { | |
thread::spawn(move || { | |
if let Ok(mut inp) = out.try_clone() { | |
let _ = io::copy(&mut inp, &mut out); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment