Skip to main content

connect

Function connect 

Source
pub async fn connect(
    simplex_daemon_url: &str,
) -> Result<(RawClient, RawEventQueue)>
Expand description

Connect to the running SimpleX daemon by websocket URI.

Returns a RawClient for sending commands and a RawEventQueue that buffers incoming chat events independently of client activity.

§Security

  • SimpleX CLI does not support TLS URIs(“wss://”) and will fail at the handshake. The web socket carries unencrypted unauthenticated traffic. Bind the daemon to localhost(ws://127.0.0.1:{port}) only. Any process or host that can reach the port has full, unauthenticated control over the daemon, can intercept events and execute arbitrary commands.

§Memory

The RawEventQueue is backed by an unbounded channel. If events are not consumed they accumulate indefinitely. Either process events promptly or drop the queue immediately if your application does not need them

§Example

let (client, events) = simploxide_core::connect("ws://127.0.0.1:5225").await?;

// (Optional) Drop the event queue if you're not planning to handle events
drop(events)

let current_user  = client.send("/user".to_owned()).await?;
println!("{}", serde_json::to_string_pretty(&current_user).unwrap());