diff --git a/src/chat/front_conn.rs b/src/chat/front_conn.rs index 117a3ae..7a50815 100644 --- a/src/chat/front_conn.rs +++ b/src/chat/front_conn.rs @@ -9,7 +9,7 @@ use async_tungstenite::{accept_async, tungstenite::Message, WebSocketStream}; use futures::{SinkExt, StreamExt}; use serde_derive::Deserialize; use std::env; -pub fn listen_client() -> io::Result<()> { +pub fn listen_client(sync: std::sync::mpsc::Sender) -> io::Result<()> { task::block_on(connect_to_client()) } diff --git a/src/main.rs b/src/main.rs index eebffcd..68341c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,34 @@ use std::{ }, thread, }; +/* + + +-----------------------------------------------------------------------------------+ + | Client | + | | + | | + | +----------------------------+ +---------------------------------+ | + | | Thread 1 | | Thread 2 | | +-------------------+ ++--------------+ | | +-----------------------+ | | +--------------------------+ | | | | +| | | | | Decode -----------------------> | | | | | +| ----------------------------> | | | | to JSON --------------------------------> | +| | | | | | | | | | | | | | +| | | | | | | | | | | | | | +| | | | +-----------------------+ | | | | | | | | +| Server | | | | | +--------------------------+ | | | Frontend | +| | | | | | | | | | +| | | | +----------------------+ | | +-----------------------------+ | | | | +| | | | | | | | | | | | | | +| | | | | Encode | | | | | | | | | +| | | | | <----------------------------- from JSON <-------------------------------- | +| | | | | | | | | | | | | | +| | | | +----------------------+ | | +-----------------------------+ | | | | ++--------------+ | | | | | | | | + | +----------------------------+ +---------------------------------+ | +-------------------+ + | | + | | + +-----------------------------------------------------------------------------------+ +*/ fn main() -> io::Result<()> { // listen_client(); @@ -34,6 +62,8 @@ fn main() -> io::Result<()> { let (server_sender, server_receiver): (Sender, Receiver) = mpsc::channel(); // server sender, server receiver let (client_sender, client_receiver): (Sender, Receiver) = mpsc::channel(); // client sender, client receiver + thread::spawn(listen_client(server_sender)); + let client_listener = thread::spawn(move || { let new_msg: MFA = client_receiver.recv().unwrap(); println!("{:?}", new_msg.encoded_msg);