Skip to content

Commit

Permalink
test(examples): socket-config-server
Browse files Browse the repository at this point in the history
  • Loading branch information
kolbma committed Jan 17, 2024
1 parent 2989a9c commit 42b80fa
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/socket-config-server.rs
@@ -0,0 +1,37 @@
#![cfg(feature = "socket2")]
extern crate tiny_http;

use std::time::Duration;

use tiny_http::{Response, Server, ServerConfig};

fn main() -> Result<(), std::io::Error> {
let server = Server::new(ServerConfig {
addr: tiny_http::ConfigListenAddr::from_socket_addrs("0.0.0.0:8000")?,
socket_config: tiny_http::SocketConfig {
read_timeout: Duration::from_millis(5000),
write_timeout: Duration::from_millis(5000),
..tiny_http::SocketConfig::default()
},
ssl: None,
})
.unwrap();

println!("server listening 0.0.0.0:8000");

for request in server.incoming_requests() {
println!(
"received request! method: {:?}, url: {:?}, headers: {:?}",
request.method(),
request.url(),
request.headers()
);

let response = Response::from_string("hello world");
request.respond(response).expect("Responded");
}

println!("server exit");

Ok(())
}

1 comment on commit 42b80fa

@kolbma
Copy link
Owner Author

@kolbma kolbma commented on 42b80fa Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also relevant for tiny-http#143

Please sign in to comment.