accept_framed

Function accept_framed 

Source
pub async fn accept_framed<T, D>(
    transport: T,
    config: HandshakeConfig,
    dispatcher: D,
) -> Result<(ConnectionHandle, IncomingConnections, Driver<T, D>), ConnectionError>
Expand description

Accept a connection with a pre-framed transport (e.g., WebSocket).

Use this when the transport already provides message framing. Returns:

  • A handle for making calls on connection 0 (root)
  • A receiver for incoming virtual connection requests
  • A driver that must be spawned

The IncomingConnections receiver allows accepting sub-connections opened by the remote peer. If you don’t need sub-connections, you can drop it and all Connect requests will be automatically rejected.

§Example

let (handle, incoming, driver) = accept_framed(transport, config, dispatcher).await?;

// Spawn the driver
spawn(driver.run());

// Optionally handle incoming connections in another task
spawn(async move {
    while let Some(conn) = incoming.recv().await {
        let sub_handle = conn.accept(vec![]).await?;
        // Use sub_handle for this virtual connection...
    }
});

// Use handle for calls on the root connection
let response = handle.call_raw(method_id, payload).await?;