helloworld/
helloworld.rs

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