From bf100f38e37a125d2a099d888b6f4a23a749f037 Mon Sep 17 00:00:00 2001 From: Mark <> Date: Tue, 11 Mar 2025 22:11:36 +0100 Subject: [PATCH] feat: support ToSocketAddrs, not just 1 SocketAddr --- musicdb-client/src/main.rs | 13 +++++++------ musicdb-lib/src/server/mod.rs | 6 +++--- musicdb-server/src/main.rs | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/musicdb-client/src/main.rs b/musicdb-client/src/main.rs index fd72e0d..ef8610e 100755 --- a/musicdb-client/src/main.rs +++ b/musicdb-client/src/main.rs @@ -2,7 +2,7 @@ use std::{ io::{BufReader, Write}, - net::{SocketAddr, TcpStream}, + net::TcpStream, path::PathBuf, sync::{Arc, Mutex}, thread, @@ -65,7 +65,7 @@ mod textcfg; #[derive(Parser, Debug)] struct Args { /// the address to be used for the tcp connection to the server - addr: SocketAddr, + addr: String, /// what to do #[command(subcommand)] mode: Mode, @@ -109,8 +109,8 @@ fn main() { // parse args let args = Args::parse(); // start - let addr = args.addr; - let mut con = TcpStream::connect(addr).unwrap(); + let addr = args.addr.clone(); + let mut con = TcpStream::connect(&addr).unwrap(); let mode = args.mode; writeln!(con, "main").unwrap(); let database = Arc::new(Mutex::new(Database::new_clientside())); @@ -130,6 +130,7 @@ fn main() { let database = Arc::clone(&database); let mut con = con.try_clone().unwrap(); // this is all you need to keep the db in sync + let addr = addr.clone(); thread::spawn(move || { #[cfg(feature = "playback")] #[cfg(not(feature = "speedy2d"))] @@ -182,7 +183,7 @@ fn main() { break 'ifstatementworkaround; } let mut db = database.lock().unwrap(); - let client_con: Box = Box::new(TcpStream::connect(addr).unwrap()); + let client_con: Box = Box::new(TcpStream::connect(&addr).unwrap()); db.remote_server_as_song_file_source = Some(Arc::new(Mutex::new( musicdb_lib::server::get::Client::new(BufReader::new(client_con)).unwrap(), ))); @@ -222,7 +223,7 @@ fn main() { let get_con: Arc>>> = Arc::new(Mutex::new( musicdb_lib::server::get::Client::new(BufReader::new(Box::new( - TcpStream::connect(addr).expect("opening get client connection"), + TcpStream::connect(&addr).expect("opening get client connection"), ) as _)) .expect("initializing get client connection"), )); diff --git a/musicdb-lib/src/server/mod.rs b/musicdb-lib/src/server/mod.rs index ee6fd93..a8cfcd0 100755 --- a/musicdb-lib/src/server/mod.rs +++ b/musicdb-lib/src/server/mod.rs @@ -2,7 +2,7 @@ pub mod get; use std::{ io::{BufRead as _, BufReader, Read, Write}, - net::{SocketAddr, TcpListener}, + net::TcpListener, sync::{mpsc, Arc, Mutex}, thread, time::Duration, @@ -269,7 +269,7 @@ impl Command { /// c) re-encode all received messages using Command::to_bytes_vec(), send them to the db, and send them to all your clients. pub fn run_server( database: Arc>, - addr_tcp: Option, + addr_tcp: Option, sender_sender: Option)>)>>, play_audio: bool, ) { @@ -277,7 +277,7 @@ pub fn run_server( } pub fn run_server_caching_thread_opt( database: Arc>, - addr_tcp: Option, + addr_tcp: Option, sender_sender: Option)>)>>, caching_thread: Option>, play_audio: bool, diff --git a/musicdb-server/src/main.rs b/musicdb-server/src/main.rs index ff5d16d..025e313 100755 --- a/musicdb-server/src/main.rs +++ b/musicdb-server/src/main.rs @@ -18,7 +18,7 @@ use musicdb_lib::data::database::Database; struct Args { /// optional address for tcp connections to the server #[arg(long)] - tcp: Option, + tcp: Option, /// optional address on which to start a website which can be used on devices without `musicdb-client` to control playback. /// requires the `assets/` folder to be present! #[arg(long)] @@ -65,7 +65,7 @@ enum Source { Remote { /// The address of another musicdb-server from where to load the songs #[arg()] - addr: SocketAddr, + addr: String, }, } // struct Args { @@ -80,7 +80,7 @@ enum Source { // init: bool, // /// optional address for tcp connections to the server // #[arg(long)] -// tcp: Option, +// tcp: Option, // /// optional address on which to start a website which can be used on devices without `musicdb-client` to control playback. // /// requires the `assets/` folder to be present! // #[arg(long)]