nothing important
This commit is contained in:
parent
16726f2fbb
commit
4012136de5
3 changed files with 19 additions and 10 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -364,9 +364,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.79"
|
||||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||
checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
@ -515,9 +515,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.58"
|
||||
version = "2.0.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
|
||||
checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -6,8 +6,9 @@ use tokio_tungstenite::{connect_async, tungstenite::protocol::Message};
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let connect_addr =
|
||||
env::args().nth(1).unwrap_or_else(|| panic!("this program requires at least one argument"));
|
||||
let connect_addr = env::args()
|
||||
.nth(1)
|
||||
.unwrap_or_else(|| panic!("this program requires at least one argument"));
|
||||
|
||||
let url = url::Url::parse(&connect_addr).unwrap();
|
||||
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -31,12 +31,18 @@ async fn handle_connection(peer_map: PeerMap, raw_stream: TcpStream, addr: Socke
|
|||
let (outgoing, incoming) = ws_stream.split();
|
||||
|
||||
let broadcast_incoming = incoming.try_for_each(|msg| {
|
||||
println!("Received a message from {}: {}", addr, msg.to_text().unwrap());
|
||||
println!(
|
||||
"Received a message from {}: {}",
|
||||
addr,
|
||||
msg.to_text().unwrap()
|
||||
);
|
||||
let peers = peer_map.lock().unwrap();
|
||||
|
||||
// We want to broadcast the message to everyone except ourselves.
|
||||
let broadcast_recipients =
|
||||
peers.iter().filter(|(peer_addr, _)| peer_addr != &&addr).map(|(_, ws_sink)| ws_sink);
|
||||
let broadcast_recipients = peers
|
||||
.iter()
|
||||
.filter(|(peer_addr, _)| peer_addr != &&addr)
|
||||
.map(|(_, ws_sink)| ws_sink);
|
||||
|
||||
for recp in broadcast_recipients {
|
||||
recp.unbounded_send(msg.clone()).unwrap();
|
||||
|
@ -58,7 +64,9 @@ async fn handle_connection(peer_map: PeerMap, raw_stream: TcpStream, addr: Socke
|
|||
async fn main() -> Result<()> {
|
||||
test()?;
|
||||
|
||||
let addr = env::args().nth(1).unwrap_or_else(|| "127.0.0.1:8080".to_string());
|
||||
let addr = env::args()
|
||||
.nth(1)
|
||||
.unwrap_or_else(|| "127.0.0.1:8080".to_string());
|
||||
|
||||
let state = PeerMap::new(Mutex::new(HashMap::new()));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue