TakClient

Struct TakClient 

Source
pub struct TakClient { /* private fields */ }
Expand description

TAK Protocol client for streaming connections to TAK servers

This client implements TAK Protocol Version 1 using Protocol Buffers. It handles the framing protocol for streaming connections and supports both plain TCP and TLS (including mTLS with client certificates).

§Example with mTLS

use takproto::{TakClient, TlsConfig, proto::CotEvent};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let tls_config = TlsConfig::new_with_client_cert(
        "ca.pem",
        "client.pem",
        "client-key.pem"
    )?;

    let mut client = TakClient::connect_tls(
        "takserver.example.com:8089",
        "takserver.example.com",
        tls_config
    ).await?;

    let event = CotEvent {
        r#type: "a-f-G-U-C".to_string(),
        uid: "RUST-1".to_string(),
        // ... other fields
        ..Default::default()
    };

    client.send_cot_event(event).await?;
    Ok(())
}

Implementations§

Source§

impl TakClient

Source

pub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>

Connect to a TAK server at the specified address using plain TCP

Note: Most production TAK servers require TLS. Use connect_tls instead.

§Arguments
  • addr - The address of the TAK server (e.g., “127.0.0.1:8087”)
§Example
let client = TakClient::connect("127.0.0.1:8087").await?;
Source

pub async fn connect_tls( addr: impl ToSocketAddrs, server_name: &str, tls_config: TlsConfig, ) -> Result<Self>

Connect to a TAK server using TLS with optional client certificate authentication (mTLS)

§Arguments
  • addr - The address of the TAK server (e.g., “takserver.example.com:8089”)
  • server_name - The server name for SNI and certificate validation
  • tls_config - TLS configuration including optional client certificates
§Example
let tls_config = TlsConfig::new_with_client_cert(
    "ca.pem",
    "client.pem",
    "client-key.pem"
)?;

let client = TakClient::connect_tls(
    "takserver.example.com:8089",
    "takserver.example.com",
    tls_config
).await?;
Source

pub async fn send_cot_event(&mut self, event: CotEvent) -> Result<()>

Send a CoT event to the TAK server

This wraps the CotEvent in a TakMessage and sends it using the TAK Protocol streaming message format.

§Arguments
  • event - The CoT event to send
§Example
let event = CotEvent {
    r#type: "a-f-G-U-C".to_string(),
    uid: "RUST-1".to_string(),
    send_time: 1234567890000,
    start_time: 1234567890000,
    stale_time: 1234567950000,
    how: "m-g".to_string(),
    lat: 37.7749,
    lon: -122.4194,
    hae: 10.0,
    ce: 9.9,
    le: 9.9,
    ..Default::default()
};
client.send_cot_event(event).await?;
Source

pub async fn send_tak_message(&mut self, message: TakMessage) -> Result<()>

Send a raw TakMessage to the server

This is a lower-level method that allows sending any TakMessage, including those with TakControl fields.

§Arguments
  • message - The TakMessage to send
Source

pub async fn receive_tak_message(&mut self) -> Result<Option<TakMessage>>

Receive a TakMessage from the server

This reads from the stream and decodes the next TAK Protocol message.

§Returns
  • Ok(Some(message)) - A message was received
  • Ok(None) - Connection was closed gracefully
  • Err(e) - An error occurred
Source

pub async fn send_cot_event_xml(&mut self, event: CotEvent) -> Result<()>

Send a CoT event as XML (Protocol Version 0)

This is used for initial communication before protocol negotiation, or when the server doesn’t support protobuf.

Source

pub async fn negotiate_protocol( &mut self, version: u32, timeout_secs: u64, ) -> Result<()>

Negotiate protocol version with TAK server

This performs the full protocol negotiation handshake:

  1. Waits for server’s TakProtocolSupport message
  2. Sends TakRequest for the specified version
  3. Waits for TakResponse confirmation

After successful negotiation, the connection is ready for protobuf messages.

§Arguments
  • version - Protocol version to negotiate (typically 1)
  • timeout - Maximum time to wait for negotiation (in seconds)
§Returns

Returns Ok(()) if negotiation succeeds, or an error if it fails or times out.

Source

pub async fn close(self) -> Result<()>

Close the connection to the TAK server

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.