Skip to content

Instantly share code, notes, and snippets.

@tilpner
Created April 10, 2016 19:40
Show Gist options
  • Save tilpner/e0376e90aad1585c925c1ce50e2453b3 to your computer and use it in GitHub Desktop.
Save tilpner/e0376e90aad1585c925c1ce50e2453b3 to your computer and use it in GitHub Desktop.
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);
}
});
}
}
}
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