Async I/O in Depth: HTTP Web Server
With this video we create an HTTP Web Server in Rust using the TcpListener and TcpStream. We implement several variations of async architectures to work with our web server. Iterative Sync requests, forking multiple processes, pre-forked processes, and a threaded model. We cover the use of a Radix Tree to implement the router for our web server. We also cover sending and reading static files as well. We cover the use of a BufWriter and BufReader to handle reading and writing to the socket rather than having to explicitly manage the buffers themselves. *Bonus:* We also make use of a colored crate to make the pid values in our terminal look a bit better.
↠ References:
BufWriter: https://doc.rust-lang.org/std/io/struct.BufWriter.html
BufReader: https://doc.rust-lang.org/std/io/struct.BufReader.html
Radix Tree: https://en.wikipedia.org/wiki/Radix_tree
std::net::TcpListener: https://doc.rust-lang.org/std/net/struct.TcpListener.html
std::net::SocketAddr: https://doc.rust-lang.org/std/net/enum.SocketAddr.html
std::net::TcpStream: https://doc.rust-lang.org/std/net/struct.TcpStream.html
std::io::Stdin: https://doc.rust-lang.org/std/io/struct.Stdin.html
std::io::Stdout: https://doc.rust-lang.org/stable/std/io/fn.stdout.html
socket: https://man7.org/linux/man-pages/man2/socket.2.html
setsocketopt: https://linux.die.net/man/2/setsockopt
bind: https://man7.org/linux/man-pages/man2/bind.2.html
listen: https://man7.org/linux/man-pages/man2/listen.2.html
connect: https://man7.org/linux/man-pages/man2/connect.2.html
write: https://man7.org/linux/man-pages/man2/write.2.html
read: https://man7.org/linux/man-pages/man2/read.2.html
close: https://man7.org/linux/man-pages/man2/close.2.html
libc crate: https://github.com/rust-lang/libc
colored crate: https://crates.io/crates/colored
↠ Dotfiles: https://github.com/nyxtom/dotfiles
↠ Twitter: @nyxtom https://twitter.com/nyxtom
↠ Channel: https://www.youtube.com/c/nyxtom
Cheers! 🍻
🦀 #rust #rustlang #rustprogramming #exercises #programming
by nyxtom 🏕
linux http server
Is the code codes available on some repository i can access?
Rust binary search could return any matching entries. Historically, it's implemented so that it returns the last entry that matches, but that behavior was never stated by the documentation and is now broken. There is no equivalent of lower_bound and upper_bound in C++.
Is there any way to make a proxy from my phone ip? Like making my phone a proxy server.
I've been trying to learn rust but it's challenging. Would be awesome to see you explaining things (many of which you may consider trivial) and creating videos for people starting to write code in rust. Btw I consider your videos really interesting.
The content is rich and I am learning a lot. Do you have a repository where we can see the code?
I think you have an issue with fork-version. It would be best to break the loop after you have handled the request (child-process). Otherwise, your end up that the system will kill you since you created too many processes.
As I understand, the fork-server has to have one process (root process) that distributes work to fork-processes. Still, the worker will become a servant in the current implementation after finishing the request, and you can see it in the logs.
timestamp: 12:17
Original PID: 56713
First child 56810
Next request root: 56713 -> everything is fine
Next request root: 56810 -> Oops, served by the child
Next request : 56713 -> everything is fine
Next request: 56811 -> hello, new boy.
I understand that it's just an example for understanding rather than a source, so it's just info to be aware of.
Also, it would be nice if you could link related videos. There is "View more" box to link videos when you mention them 🙂
E.g.: tree -> https://www.youtube.com/watch?v=wDnI8liqD-o
I think it's an excellent time to create a Patreon. Your videos are outstanding, so it would be nice to have the ability to give a penny for that 🙂
explanation is still not very clear but improved.
Your explanation and video quality is improving. Gread job sir!
🍻🍻