publish_tcp/
publish_tcp.rs

1#[tokio::main]
2async fn main() -> Result<(), String> {
3    let client_type = simple_pub_sub::client::PubSubTcpClient {
4        server: "localhost".to_string(),
5        port: 6480,
6        cert: None,
7        cert_password: None,
8    };
9
10    // initialize the client.
11    let mut client =
12        simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
13    // connect the client.
14    let _ = client.connect().await;
15    // subscribe to the given topic.
16    let _ = client
17        .publish(
18            "abc".to_string(),
19            "test message".to_string().into_bytes().to_vec(),
20        )
21        .await;
22    Ok(())
23}