find out way to communicate
This commit is contained in:
parent
4916f96345
commit
ddcc5e48a8
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
30
src/main.rs
30
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<MFA>, Receiver<MFA>) = mpsc::channel(); // server sender, server receiver
|
||||
let (client_sender, client_receiver): (Sender<MFA>, Receiver<MFA>) = 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);
|
||||
|
|
Loading…
Reference in a new issue