pub struct Client<'a> { /* private fields */ }Expand description
Allows interaction as a client with a WAMP server
Implementations§
Source§impl<'a> Client<'a>
impl<'a> Client<'a>
Sourcepub async fn connect<T: AsRef<str>>(
uri: T,
cfg: Option<ClientConfig>,
) -> Result<(Client<'a>, (GenericFuture<'a>, Option<UnboundedReceiver<GenericFuture<'a>>>)), WampError>
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
Sourcepub async fn join_realm<T: Into<String>>(
&mut self,
realm: T,
) -> Result<(), WampError>
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
Sourcepub 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,
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 realmauthentication_methods- A set of all the authentication methods the client will supportauthentication_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?;Sourcepub async fn leave_realm(&mut self) -> Result<(), WampError>
pub async fn leave_realm(&mut self) -> Result<(), WampError>
Leaves the current realm and terminates the session with the server
Sourcepub async fn subscribe<T: AsRef<str>>(
&self,
topic: T,
) -> Result<(WampId, UnboundedReceiver<(WampId, Option<WampArgs>, Option<WampKwArgs>)>), WampError>
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.
Sourcepub async fn unsubscribe(&self, sub_id: WampId) -> Result<(), WampError>
pub async fn unsubscribe(&self, sub_id: WampId) -> Result<(), WampError>
Unsubscribes to a previously subscribed topic
Sourcepub async fn publish<T: AsRef<str>>(
&self,
topic: T,
arguments: Option<WampArgs>,
arguments_kw: Option<WampKwArgs>,
acknowledge: bool,
) -> Result<Option<WampId>, WampError>
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.
Sourcepub async fn register<T, F, Fut>(
&self,
uri: T,
func_ptr: F,
) -> Result<WampId, WampError>
pub async fn register<T, F, Fut>( &self, uri: T, func_ptr: F, ) -> Result<WampId, WampError>
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()
Sourcepub async fn unregister(&self, rpc_id: WampId) -> Result<(), WampError>
pub async fn unregister(&self, rpc_id: WampId) -> Result<(), WampError>
Unregisters an RPC endpoint
Sourcepub async fn call<T: AsRef<str>>(
&self,
uri: T,
arguments: Option<WampArgs>,
arguments_kw: Option<WampKwArgs>,
) -> Result<(Option<WampArgs>, Option<WampKwArgs>), WampError>
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
Sourcepub fn get_cur_status(&mut self) -> &ClientState
pub fn get_cur_status(&mut self) -> &ClientState
Returns the current client status
Sourcepub fn is_connected(&mut self) -> bool
pub fn is_connected(&mut self) -> bool
Returns whether we are connected to the server or not
Sourcepub async fn block_until_disconnect(&mut self) -> &ClientState
pub async fn block_until_disconnect(&mut self) -> &ClientState
Blocks the caller until the connection with the server is terminated
Sourcepub async fn disconnect(self)
pub async fn disconnect(self)
Cleanly closes a connection with the server