helloworld/helloworld.rs
1#[cfg(feature = "server")]
2fn main() {
3 use ehttpd::{
4 Server,
5 http::{Response, ResponseExt},
6 };
7
8 // Create a server that listens at [::]:9999 with up to 2048 worker threads under load if necessary
9 let server = Server::with_request_response(2048, |_| {
10 let mut response = Response::new_200_ok();
11 response.set_body_data(b"Hello world\r\n");
12 response
13 });
14
15 // Handle incoming connections
16 server.accept("[::]:9999").expect("server failed");
17}
18
19#[cfg(not(feature = "server"))]
20fn main() {
21 panic!("The `server`-feature must be enabled for this example to run")
22}