pub struct SeedLinkClient { /* private fields */ }Expand description
Async SeedLink client for connecting to seismic data servers.
Implements the SeedLink v3/v4 protocol state machine:
Connected → Configured → Streaming → Disconnected.
§Example
use seedlink_rs_client::SeedLinkClient;
let mut client = SeedLinkClient::connect("rtserve.iris.washington.edu:18000").await?;
client.station("ANMO", "IU").await?;
client.select("BHZ").await?;
client.data().await?;
client.end_stream().await?;
while let Some(frame) = client.next_frame().await? {
println!("seq={}, len={}", frame.sequence(), frame.payload().len());
}Implementations§
Source§impl SeedLinkClient
impl SeedLinkClient
Sourcepub async fn connect(addr: &str) -> Result<Self>
pub async fn connect(addr: &str) -> Result<Self>
Connect to a SeedLink server with default configuration.
Performs TCP connect, sends HELLO, and negotiates v4 if supported.
On success the client is in ClientState::Connected.
Sourcepub async fn connect_with_config(
addr: &str,
config: ClientConfig,
) -> Result<Self>
pub async fn connect_with_config( addr: &str, config: ClientConfig, ) -> Result<Self>
Connect to a SeedLink server with custom ClientConfig.
Performs TCP connect, sends HELLO, and optionally negotiates v4.
On success the client is in ClientState::Connected.
Sourcepub fn version(&self) -> ProtocolVersion
pub fn version(&self) -> ProtocolVersion
Returns the negotiated protocol version (V3 or V4).
Sourcepub fn server_info(&self) -> &ServerInfo
pub fn server_info(&self) -> &ServerInfo
Returns information about the connected server (software, version, capabilities).
Sourcepub fn state(&self) -> ClientState
pub fn state(&self) -> ClientState
Returns the current client state.
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Returns the configuration used for this connection.
Sourcepub async fn station(&mut self, station: &str, network: &str) -> Result<()>
pub async fn station(&mut self, station: &str, network: &str) -> Result<()>
Select a station and network for data subscription.
Requires state Connected or Configured. Transitions to Configured.
Server must reply OK; returns ClientError::ServerError on ERROR.
Sourcepub async fn select(&mut self, pattern: &str) -> Result<()>
pub async fn select(&mut self, pattern: &str) -> Result<()>
Select channels within the current station subscription.
pattern is a SeedLink channel selector (e.g., "BHZ", "??.BHZ").
Requires state Connected or Configured. Transitions to Configured.
Sourcepub async fn data(&mut self) -> Result<()>
pub async fn data(&mut self) -> Result<()>
Arm the current station subscription with DATA (stream from beginning).
This does NOT start streaming — call end_stream() or
fetch() after arming all stations.
Requires state Configured. State stays Configured.
Sourcepub async fn data_from(&mut self, sequence: SequenceNumber) -> Result<()>
pub async fn data_from(&mut self, sequence: SequenceNumber) -> Result<()>
Arm the current station subscription with DATA, resuming from sequence.
Requires state Configured. State stays Configured.
Sourcepub async fn time_window(
&mut self,
start: &str,
end: Option<&str>,
) -> Result<()>
pub async fn time_window( &mut self, start: &str, end: Option<&str>, ) -> Result<()>
Arm the current station subscription with a time window (v3 only).
Sends TIME start [end] to request data within a specific time range.
Requires state Configured. State stays Configured.
Sourcepub async fn end_stream(&mut self) -> Result<()>
pub async fn end_stream(&mut self) -> Result<()>
Send END to trigger continuous binary streaming.
The server begins sending frames immediately with no text response.
Requires state Configured. Transitions to Streaming.
Sourcepub async fn fetch(&mut self) -> Result<()>
pub async fn fetch(&mut self) -> Result<()>
Send FETCH to stream buffered data then close (v3 only).
Unlike end_stream(), FETCH delivers only what the
server has buffered, then the server closes the connection.
Requires state Configured. Transitions to Streaming.
Sourcepub async fn fetch_from(&mut self, sequence: SequenceNumber) -> Result<()>
pub async fn fetch_from(&mut self, sequence: SequenceNumber) -> Result<()>
Send FETCH resuming from sequence (v3 only).
Requires state Configured. Transitions to Streaming.
Sourcepub async fn next_frame(&mut self) -> Result<Option<OwnedFrame>>
pub async fn next_frame(&mut self) -> Result<Option<OwnedFrame>>
Read the next SeedLink frame from the server.
Returns Ok(Some(frame)) on success, Ok(None) on clean EOF
(server closed connection), or Err on protocol/timeout errors.
On EOF, state transitions to Disconnected.
Requires state Streaming.
Sourcepub fn into_stream(self) -> impl Stream<Item = Result<OwnedFrame>>
pub fn into_stream(self) -> impl Stream<Item = Result<OwnedFrame>>
Consume this client and return a Stream of frames.
The client must be in Streaming state. The stream yields
Ok(OwnedFrame) per frame and ends with None on EOF.
Sourcepub async fn info(&mut self, level: InfoLevel) -> Result<Vec<OwnedFrame>>
pub async fn info(&mut self, level: InfoLevel) -> Result<Vec<OwnedFrame>>
Request server information at the given detail level.
Returns a vec of INFO response frames (typically XML payloads). Can be called in any state.
Sourcepub async fn bye(&mut self) -> Result<()>
pub async fn bye(&mut self) -> Result<()>
Send BYE and close the connection.
Transitions to Disconnected. Can be called in any state.
Sourcepub fn last_sequence(
&self,
network: &str,
station: &str,
) -> Option<SequenceNumber>
pub fn last_sequence( &self, network: &str, station: &str, ) -> Option<SequenceNumber>
Returns the last received sequence number for a given network/station pair.
Returns None if no frames have been received for that station.
Sourcepub fn sequences(&self) -> &HashMap<StationKey, SequenceNumber>
pub fn sequences(&self) -> &HashMap<StationKey, SequenceNumber>
Returns a reference to all tracked network/station → sequence mappings.