Multithreaded Web Server Made with Rust

Overview

Multithreaded Web Server Made with Rust

The server listens for TCP connections at address 127.0.0.1:7878. Several pages can be accessed:

  • 127.0.0.1:7878 - Default page, simple HTML.
  • 127.0.0.1:7878/sleep - Server responds with a 5 second delay. This is made for testing its multithreaded aspect.
  • 127.0.0.1:7878/shutdown - Asks for the password, and if it's correctly provided, shuts the server down. The password is rust7878.
  • 127.0.0.1:7878/[non-existent link] - Gives us the "404 Not Found" page.

How to Run

To run this project, you must have cargo installed. Open the base directory and run the following command:

cargo run

The server can be shut down either by pressing Ctrl + C in the terminal or visiting the shutdown page and providing the correct password.

Implementation Details

This project is partially based on the final project from The Rust Programming Language book.

Multithreading is done with thread pool. The code is split in two files: main.rs and lib.rs. The name of the crate is hello_web.

  • lib.rs contains the implementation of the public ThreadPool struct, which manages the worker threads, defined by the Worker struct.
  • main.rs contains the code responsible for getting HTTP requests and sending appropriate responses with the handle_connection function.

Each worker thread receives the handle_connection function as well as the callback function that should be called for shutting down the server. Each job (or task) given to the worker threads returns the ThreadPoolStatus enum which tells them whether the server needs to be shut down after completing the job.

You might also like...
An implementation of the classic arcade game Whac-A-Hole inside Discord, made in 12 hours, with no experience in Rust.

Whac-A-Hole A blazingly fast implementation of the classic arcade game What-A-Hole inside Discord, made in 12 hours, with no experience in Rust ( πŸš€ ?

A halloween-themed game made in Rust πŸ¦€

Robo Halloween πŸ€– πŸŽƒ 🧟 Top 3 pumpkin smashers πŸŽ‰ 🦾 πŸ₯‡ poteresting - 80 πŸŽƒ πŸ₯ˆ ArinaSolovjova - 69 πŸŽƒ πŸ₯‰ poteresting - 61 πŸŽƒ Get your name on this boa

Rust crate for configurable parallel web crawling, designed to crawl for content

url-crawler A configurable parallel web crawler, designed to crawl a website for content. Changelog Docs.rs Example extern crate url_crawler; use std:

A multiplayer web based roguelike built on Rust and WebRTC
A multiplayer web based roguelike built on Rust and WebRTC

Gorgon A multiplayer web-based roguelike build on Rust and WebRTC. License This project is licensed under either of Apache License, Version 2.0, (LICE

 Crusty - polite && scalable broad web crawler
Crusty - polite && scalable broad web crawler

Broad web crawling is an activity of going through practically boundless web by starting from a set of locations(urls) and following outgoing links. Usually it doesn't matter where you start from as long as it has outgoing links to external domains.

The open source distributed web search engine that searches by meaning.

DawnSearch DawnSearch is an open source distributed web search engine that searches by meaning. It uses semantic search (searching on meaning), using

Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo workspace

ra-multiplex   Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo wor

A telnet chat server written in Rust, running on Lunatic.
A telnet chat server written in Rust, running on Lunatic.

Lunatic.chat A telnet chat server written in Rust, running on Lunatic. If you just would like to try it out, join the hosted version with: # US server

Owner
Simply not there
null
Grow Rust is a Growtopia Private Server made in Rust

Grow Rust is a Growtopia Private Server made in Rust

null 14 Dec 7, 2022
Getting the token's holder info and pushing to a web server.

Purpose of this program I've made this web scraper so you can use it to get the holder's amount from BSCscan and it will upload for you in JSON format

null 3 Jul 7, 2022
An efficient web server for TiddlyWikis.

Tiddlywiki Server This is a web backend for TiddlyWiki. It uses TiddlyWiki's web server API to save tiddlers in a [SQLite database]. It should come wi

Nathaniel Knight 17 Nov 19, 2022
DNS Server written in Rust for fun, see https://dev.to/xfbs/writing-a-dns-server-in-rust-1gpn

DNS Fun Ever wondered how you can write a DNS server in Rust? No? Well, too bad, I'm telling you anyways. But don't worry, this is going to be a fun o

Patrick Elsen 26 Jan 13, 2023
Dav-server-rs - Rust WebDAV server library. A fork of the webdav-handler crate.

dav-server-rs A fork of the webdav-handler-rs project. Generic async HTTP/Webdav handler Webdav (RFC4918) is defined as HTTP (GET/HEAD/PUT/DELETE) plu

messense 30 Dec 29, 2022
axum-server is a hyper server implementation designed to be used with axum framework.

axum-server axum-server is a hyper server implementation designed to be used with axum framework. Features Conveniently bind to any number of addresse

null 79 Jan 4, 2023
Jex Compiler Server - Server that runs Jex code

Server that compiles and runs Jex code.

furetur 3 Nov 18, 2021
QUIC proxy that allows to use QUIC to connect to an SSH server without needing to patch the client or the server.

quicssh-rs ?? quicssh-rs is a QUIC proxy that allows to use QUIC to connect to an SSH server without needing to patch the client or the server. quicss

Jun Ouyang 18 May 5, 2023
Send files over TCP. Quick and simple. Made in Rust.

SFT Multithreaded utility to send files over TCP. The sender writes a header containing the filename, and then the contents of the file, buffered, to

Orel 0 Dec 24, 2021
A really basic Cloudflare worker made in rust

Rust WebAssembly Worker. A really basic Cloudflare worker made in rust.

Bram 4 Nov 17, 2022