Client

Struct Client 

Source
pub struct Client<'a> { /* private fields */ }
Expand description

Allows interaction as a client with a WAMP server

Implementations§

Source§

impl<'a> Client<'a>

Source

pub async fn connect<T: AsRef<str>>( uri: T, cfg: Option<ClientConfig>, ) -> Result<(Client<'a>, (GenericFuture<'a>, Option<UnboundedReceiver<GenericFuture<'a>>>)), WampError>

Connects to a WAMP server using the specified protocol

Note

On success, this function returns :

  • Client : Used to interact with the server
  • Main event loop Future : This MUST be spawned by the caller (e.g using tokio::spawn())
  • RPC event queue : If you register RPC endpoints, you MUST spawn a seperate task to also handle these events

To customize parmeters used for the connection, see the ClientConfig struct

Source

pub async fn join_realm<T: Into<String>>( &mut self, realm: T, ) -> Result<(), WampError>

Attempts to join a realm and start a session with the server.

  • realm - A name of the WAMP realm
Source

pub async fn join_realm_with_authentication<Realm, AuthenticationId, AuthenticationChallengeHandler, AuthenticationChallengeHandlerResponse>( &mut self, realm: Realm, authentication_methods: Vec<AuthenticationMethod>, authentication_id: AuthenticationId, on_challenge_handler: AuthenticationChallengeHandler, ) -> Result<(), WampError>
where Realm: Into<String>, AuthenticationId: Into<String>, AuthenticationChallengeHandler: Fn(AuthenticationMethod, WampDict) -> AuthenticationChallengeHandlerResponse + Send + Sync + 'a, AuthenticationChallengeHandlerResponse: Future<Output = Result<AuthenticationChallengeResponse, WampError>> + Send + 'a,

Attempts to join a realm and start a session with the server.

  • realm - A name of the WAMP realm
  • authentication_methods - A set of all the authentication methods the client will support
  • authentication_id - An authentication ID (e.g. username) the client wishes to authenticate as. It is required for non-anynomous authentication methods.
  • on_challenge_handler - An authentication handler function
client
    .join_realm_with_authentication(
        "realm1",
        vec![wamp_async::AuthenticationMethod::Ticket],
        "username",
        |_authentication_method, _extra| async {
            Ok(wamp_async::AuthenticationChallengeResponse::with_signature(
                "password".into(),
            ))
        },
    )
    .await?;
Source

pub async fn leave_realm(&mut self) -> Result<(), WampError>

Leaves the current realm and terminates the session with the server

Source

pub async fn subscribe<T: AsRef<str>>( &self, topic: T, ) -> Result<(WampId, UnboundedReceiver<(WampId, Option<WampArgs>, Option<WampKwArgs>)>), WampError>

Subscribes to events for the specifiec topic

This function returns a subscription ID (required to unsubscribe) and the receive end of a channel for events published on the topic.

Source

pub async fn unsubscribe(&self, sub_id: WampId) -> Result<(), WampError>

Unsubscribes to a previously subscribed topic

Source

pub async fn publish<T: AsRef<str>>( &self, topic: T, arguments: Option<WampArgs>, arguments_kw: Option<WampKwArgs>, acknowledge: bool, ) -> Result<Option<WampId>, WampError>

Publishes an event on a specific topic

The caller can set acknowledge to true to receive unique IDs from the server for each published event.

Source

pub async fn register<T, F, Fut>( &self, uri: T, func_ptr: F, ) -> Result<WampId, WampError>
where T: AsRef<str>, F: Fn(Option<WampArgs>, Option<WampKwArgs>) -> Fut + Send + Sync + 'a, Fut: Future<Output = Result<(Option<WampArgs>, Option<WampKwArgs>), WampError>> + Send + 'a,

Register an RPC endpoint. Upon succesful registration, a registration ID is returned (used to unregister) and calls received from the server will generate a future which will be sent on the rpc event channel returned by the call to event_loop()

Source

pub async fn unregister(&self, rpc_id: WampId) -> Result<(), WampError>

Unregisters an RPC endpoint

Source

pub async fn call<T: AsRef<str>>( &self, uri: T, arguments: Option<WampArgs>, arguments_kw: Option<WampKwArgs>, ) -> Result<(Option<WampArgs>, Option<WampKwArgs>), WampError>

Calls a registered RPC endpoint on the server

Source

pub fn get_cur_status(&mut self) -> &ClientState

Returns the current client status

Source

pub fn is_connected(&mut self) -> bool

Returns whether we are connected to the server or not

Source

pub async fn block_until_disconnect(&mut self) -> &ClientState

Blocks the caller until the connection with the server is terminated

Source

pub async fn disconnect(self)

Cleanly closes a connection with the server

Auto Trait Implementations§

§

impl<'a> Freeze for Client<'a>

§

impl<'a> RefUnwindSafe for Client<'a>

§

impl<'a> Send for Client<'a>

§

impl<'a> Sync for Client<'a>

§

impl<'a> Unpin for Client<'a>

§

impl<'a> UnwindSafe for Client<'a>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,