Building an HTTP server using Hyper
When it comes to running an HTTP server with Hyper, we will be using Tokio. We have two actors running and two channels to facilitate the communication between actors and requests. First, in the main
function, we define the address of the server with the following code:
#[tokio::main] async fn main() { let addr = SocketAddr::from(([0, 0, 0, 0], 3000)); . . . }
After the address is defined, we define the two channels for messages with the following code:
let (state_tx, state_rx) = mpsc::channel::<StateActorMessage>(1); let (runner_tx, runner_rx) = mpsc::channel::<StateActorMessage>(1); let channel_sender = state_tx.clone();
We clone the sender for the state actor because we will pass the sender through the handle
function with the incoming request. Now that we have our channels, we can spin off two threads to run our actors with...