mirror of
https://codeberg.org/demostf/sync.git
synced 2026-06-03 16:44:07 +02:00
make port configurable
This commit is contained in:
parent
5e853f76e2
commit
3edc7acf2d
1 changed files with 5 additions and 6 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -60,8 +60,6 @@ fn handle_command(command: SyncCommand, sessions: &mut HashMap<String, Session>,
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
for peer in ws.get_connected().unwrap() {
|
for peer in ws.get_connected().unwrap() {
|
||||||
if peer != client {
|
if peer != client {
|
||||||
println!("-> relaying to peer {:?}", peer);
|
|
||||||
|
|
||||||
let response = WebSocketEvent::TextMessage(command_text.clone());
|
let response = WebSocketEvent::TextMessage(command_text.clone());
|
||||||
ws.send((peer, response));
|
ws.send((peer, response));
|
||||||
}
|
}
|
||||||
|
|
@ -82,8 +80,6 @@ fn handle_command(command: SyncCommand, sessions: &mut HashMap<String, Session>,
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
for peer in ws.get_connected().unwrap() {
|
for peer in ws.get_connected().unwrap() {
|
||||||
if peer != client {
|
if peer != client {
|
||||||
println!("-> relaying to peer {:?}", peer);
|
|
||||||
|
|
||||||
let response = WebSocketEvent::TextMessage(command_text.clone());
|
let response = WebSocketEvent::TextMessage(command_text.clone());
|
||||||
ws.send((peer, response));
|
ws.send((peer, response));
|
||||||
}
|
}
|
||||||
|
|
@ -97,9 +93,13 @@ fn handle_command(command: SyncCommand, sessions: &mut HashMap<String, Session>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let port = std::env::var("PORT").unwrap_or("80".to_string());
|
||||||
|
let listen = format!("0.0.0.0:{}", port);
|
||||||
let mut sessions: HashMap<String, Session> = HashMap::new();
|
let mut sessions: HashMap<String, Session> = HashMap::new();
|
||||||
|
|
||||||
let mut ws = WebSocket::new("0.0.0.0:10000".parse::<SocketAddr>().unwrap());
|
let mut ws = WebSocket::new(listen.parse::<SocketAddr>().unwrap());
|
||||||
|
|
||||||
|
println!("listening on: {:?}", listen);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match ws.next() {
|
match ws.next() {
|
||||||
|
|
@ -118,7 +118,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
(tok, WebSocketEvent::BinaryMessage(msg)) => {
|
(tok, WebSocketEvent::BinaryMessage(msg)) => {
|
||||||
println!("msg from {:?}", tok);
|
|
||||||
let response = WebSocketEvent::BinaryMessage(msg.clone());
|
let response = WebSocketEvent::BinaryMessage(msg.clone());
|
||||||
ws.send((tok, response));
|
ws.send((tok, response));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue