Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -5,7 +5,7 @@ my $socket = IO::Socket::INET.new:
|
|||
|
||||
while $socket.accept -> $conn {
|
||||
say "Accepted connection";
|
||||
async {
|
||||
start {
|
||||
while $conn.recv -> $stuff {
|
||||
say "Echoing $stuff";
|
||||
$conn.send($stuff);
|
||||
|
|
|
|||
27
Task/Echo-server/Rust/echo-server.rust
Normal file
27
Task/Echo-server/Rust/echo-server.rust
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use std::net::{TcpListener, TcpStream};
|
||||
use std::io::{BufReader, BufRead, Write};
|
||||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
let listener = TcpListener::bind("127.0.0.1:12321").unwrap();
|
||||
println!("server is running on 127.0.0.1:12321 ...");
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let stream = stream.unwrap();
|
||||
thread::spawn(move || handle_client(stream));
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_client(stream: TcpStream) {
|
||||
let mut stream = BufReader::new(stream);
|
||||
loop {
|
||||
let mut buf = String::new();
|
||||
if stream.read_line(&mut buf).is_err() {
|
||||
break;
|
||||
}
|
||||
stream
|
||||
.get_ref()
|
||||
.write(buf.as_bytes())
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue