Web server without using libs, that implements http

HI guys i'm writing web-server in my university task. The task sounds as: implement web server for serving static files. I can use libraries which helps manage tcp connections, but I can't use libraries that implement any part of http and multithreading. I've decided to use Rust, and use following architecture: use multithreading to serve user connection and use non blocking sockets (maybe like epoll in c), but i cant understand which lib use to manage tcp connections and how correctly serve connections with multithreading. I've heard about crate mio, but also i cant understand how to handle connections inside threads. Can you give me advice?

1 Like

You probably want to start with tokio, which handles async I/O. (It also has a thread pool implementation, but you don't have to use it.) Check out the tokio documentation and getting start guides, see where it takes you!

Do you have to use async (socket) I/O? If not and/or you’re unfamiliar with async I/O, it may be simpler to stick to a thread-per-request model. If that’s fine, then you should be able to use Rust’s stdlib to accomplish this.

If you want or need to use async I/O, then tokio can work as @parasyte mentioned. It has a somewhat steep learning curve, particularly if you’re not already comfortable with Rust in general. But, this example may give you a good starting point.

Mio is a bit lower level than tokio, but some people find it easier than tokio (particularly if they know how to use epoll). If you’re seeing yourself not taking well to tokio, try mio.

2 Likes