diff --git a/crates/top/rerun/src/run.rs b/crates/top/rerun/src/run.rs index 46d7a1fa10eee..596e3388deee4 100644 --- a/crates/top/rerun/src/run.rs +++ b/crates/top/rerun/src/run.rs @@ -887,6 +887,7 @@ fn run_impl( ) -> anyhow::Result<()> { #[cfg(feature = "native_viewer")] let profiler = profiler(&args); + let mut is_another_viewer_running = false; #[cfg(feature = "native_viewer")] let startup_options = { @@ -951,13 +952,26 @@ fn run_impl( #[cfg(feature = "server")] { - let server_options = re_sdk_comms::ServerOptions { - max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()), - quiet: false, - }; - let tcp_listener: Receiver = - re_sdk_comms::serve(&args.bind, args.port, server_options)?; - rxs.push(tcp_listener); + // Check if there is already a viewer running + // and if so, send the data to it. + use std::net::TcpStream; + let connect_addr = std::net::SocketAddr::new(args.bind.parse().unwrap(), args.port); + if TcpStream::connect_timeout(&connect_addr, std::time::Duration::from_secs(1)).is_ok() + { + re_log::info!( + addr = %connect_addr, + "A process is already listening at this address. Assuming it's a Rerun Viewer." + ); + is_another_viewer_running = true; + } else { + let server_options = re_sdk_comms::ServerOptions { + max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()), + quiet: false, + }; + let tcp_listener: Receiver = + re_sdk_comms::serve(&args.bind, args.port, server_options)?; + rxs.push(tcp_listener); + } } rxs @@ -1030,6 +1044,22 @@ fn run_impl( return Ok(()); } + } else if is_another_viewer_running { + re_log::info!("Another viewer is already running, streaming data to it."); + // get current active recording + use re_sdk::RecordingStream; + let static_ = true; + + let Some(active_recording) = RecordingStream::get(re_sdk::StoreKind::Recording, None) + else { + anyhow::bail!("No active recording found!"); + }; + // map is lazy, so we need take the result by let _ = ... + let _ = args + .url_or_paths + .iter() + .map(|path| active_recording.log_file_from_path(path, None, static_)); + Ok(()) } else { #[cfg(feature = "native_viewer")] return re_viewer::run_native_app(