29 lines
650 B
Rust
29 lines
650 B
Rust
use std::sync::Arc;
|
|
use std::thread;
|
|
|
|
fn main() {
|
|
start_server();
|
|
}
|
|
|
|
fn start_server() {
|
|
let server = Arc::new(tiny_http::Server::http("0.0.0.0:33333").unwrap());
|
|
println!("Server listening on port 33333");
|
|
|
|
let mut handles = Vec::with_capacity(4);
|
|
|
|
for _ in 0..4 {
|
|
let server = server.clone();
|
|
|
|
handles.push(thread::spawn(move || {
|
|
for rq in server.incoming_requests() {
|
|
let response = tiny_http::Response::from_string("hello world".to_string());
|
|
let _ = rq.respond(response);
|
|
}
|
|
}));
|
|
}
|
|
|
|
for h in handles {
|
|
h.join().unwrap();
|
|
}
|
|
}
|