Responding with TCP
When it comes to responding to TCP, we must implement our actor system in the src/main.rs
file. First, we need to import our new actors with the following code:
. . . use order_tracker::{TrackerActor, GetTrackerActor, TrackerMessage};
Now, we must construct our extra channel in the main
function with the following code:
let addr = "127.0.0.1:8080".to_string(); let socket = TcpListener::bind(&addr).await.unwrap(); println!("Listening on: {}", addr); let (tx, rx) = mpsc::channel::<Message>(1); let (tracker_tx, tracker_rx) = mpsc::channel::<TrackerMessage>(1); let tracker_tx_one = tracker_tx.clone();
Here, we have a tracker
channel. With the tracker
and main
channels, we can spin up two different threads with the tracker actor and order book actor with the following code:
tokio...