Skip to content

Commit 213aa1d

Browse files
When launched with a file path, the viewer will now still listen for TCP connections (#6951)
1 parent fd7b8e6 commit 213aa1d

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

crates/top/rerun/src/commands/entrypoint.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ fn run_impl(
613613
) -> anyhow::Result<()> {
614614
#[cfg(feature = "native_viewer")]
615615
let profiler = run_profiler(&args);
616+
let mut is_another_viewer_running = false;
616617

617618
#[cfg(feature = "native_viewer")]
618619
let startup_options = {
@@ -655,20 +656,7 @@ fn run_impl(
655656
};
656657

657658
// Where do we get the data from?
658-
let rx: Vec<Receiver<LogMsg>> = if args.url_or_paths.is_empty() {
659-
#[cfg(feature = "server")]
660-
{
661-
let server_options = re_sdk_comms::ServerOptions {
662-
max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()),
663-
quiet: false,
664-
};
665-
let rx = re_sdk_comms::serve(&args.bind, args.port, server_options)?;
666-
vec![rx]
667-
}
668-
669-
#[cfg(not(feature = "server"))]
670-
vec![]
671-
} else {
659+
let rx: Vec<Receiver<LogMsg>> = {
672660
let data_sources = args
673661
.url_or_paths
674662
.iter()
@@ -697,10 +685,35 @@ fn run_impl(
697685
}
698686
}
699687

700-
data_sources
688+
let mut rxs = data_sources
701689
.into_iter()
702690
.map(|data_source| data_source.stream(None))
703-
.collect::<Result<Vec<_>, _>>()?
691+
.collect::<Result<Vec<_>, _>>()?;
692+
693+
#[cfg(feature = "server")]
694+
{
695+
// Check if there is already a viewer running and if so, send the data to it.
696+
use std::net::TcpStream;
697+
let connect_addr = std::net::SocketAddr::new("127.0.0.1".parse().unwrap(), args.port);
698+
if TcpStream::connect_timeout(&connect_addr, std::time::Duration::from_secs(1)).is_ok()
699+
{
700+
re_log::info!(
701+
addr = %connect_addr,
702+
"A process is already listening at this address. Assuming it's a Rerun Viewer."
703+
);
704+
is_another_viewer_running = true;
705+
} else {
706+
let server_options = re_sdk_comms::ServerOptions {
707+
max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()),
708+
quiet: false,
709+
};
710+
let tcp_listener: Receiver<LogMsg> =
711+
re_sdk_comms::serve(&args.bind, args.port, server_options)?;
712+
rxs.push(tcp_listener);
713+
}
714+
}
715+
716+
rxs
704717
};
705718

706719
// Now what do we do with the data?
@@ -772,6 +785,9 @@ fn run_impl(
772785

773786
return Ok(());
774787
}
788+
} else if is_another_viewer_running {
789+
re_log::info!("Another viewer is already running, streaming data to it.");
790+
Ok(())
775791
} else {
776792
#[cfg(feature = "native_viewer")]
777793
return re_viewer::run_native_app(

0 commit comments

Comments
 (0)