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
impl TakClient
Sourcepub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>
pub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>
Sourcepub async fn connect_tls(
addr: impl ToSocketAddrs,
server_name: &str,
tls_config: TlsConfig,
) -> Result<Self>
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 validationtls_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?;Sourcepub async fn send_cot_event(&mut self, event: CotEvent) -> Result<()>
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?;Sourcepub async fn send_tak_message(&mut self, message: TakMessage) -> Result<()>
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
Sourcepub async fn receive_tak_message(&mut self) -> Result<Option<TakMessage>>
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 receivedOk(None)- Connection was closed gracefullyErr(e)- An error occurred
Sourcepub async fn send_cot_event_xml(&mut self, event: CotEvent) -> Result<()>
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.
Sourcepub async fn negotiate_protocol(
&mut self,
version: u32,
timeout_secs: u64,
) -> Result<()>
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:
- Waits for server’s TakProtocolSupport message
- Sends TakRequest for the specified version
- 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.