Created
April 10, 2016 19:40
-
-
Save tilpner/e0376e90aad1585c925c1ce50e2453b3 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
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); | |
} | |
}); | |
} | |
} | |
} |
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::{BufRead, BufReader, Write}; | |
use std::net::TcpStream; | |
fn main() { | |
let mut stream = TcpStream::connect("127.0.0.1:12345").unwrap(); | |
stream.write_all(b"Test\r\n").unwrap(); | |
let bufreader = BufReader::new(stream); | |
for line in bufreader.lines().filter_map(Result::ok) { | |
println!("{}", line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment