pub struct MqttClient { /* private fields */ }
Expand description
The client for connecting to the MQTT server
Implementations§
Source§impl MqttClient
impl MqttClient
Sourcepub fn new<TReader: AsyncRead + Send + 'static + Unpin, TWriter: AsyncWrite + Send + 'static + Unpin>(
reader: TReader,
writer: TWriter,
client_name: String,
options: MqttOptions,
message_recipient: Recipient<PublishMessage>,
error_recipient: Recipient<ErrorMessage>,
stop_recipient: Option<Recipient<StopMessage>>,
) -> Self
pub fn new<TReader: AsyncRead + Send + 'static + Unpin, TWriter: AsyncWrite + Send + 'static + Unpin>( reader: TReader, writer: TWriter, client_name: String, options: MqttOptions, message_recipient: Recipient<PublishMessage>, error_recipient: Recipient<ErrorMessage>, stop_recipient: Option<Recipient<StopMessage>>, ) -> Self
Create a new MQTT client
Sourcepub async fn connect(&mut self) -> Result<(), IoError>
pub async fn connect(&mut self) -> Result<(), IoError>
Perform the connect operation to the remote MQTT server
Note: This function can only be called once for each client, calling it the second time will return an error Note: The successful return of this function DOES NOT mean that the MQTT connection is successful, if anything wrong happens the error actor will receive an error Note: Please use is_connected() to check whether the MQTT connection is successful or not
Sourcepub async fn is_connected(&self) -> IoResult<bool>
pub async fn is_connected(&self) -> IoResult<bool>
Check whether the client has connected to the server successfully
Sourcepub async fn subscribe(
&self,
topic: String,
qos: QualityOfService,
) -> Result<(), IoError>
pub async fn subscribe( &self, topic: String, qos: QualityOfService, ) -> Result<(), IoError>
Subscribe to the server with a topic and QoS
Sourcepub async fn unsubscribe(&self, topic: String) -> Result<(), IoError>
pub async fn unsubscribe(&self, topic: String) -> Result<(), IoError>
Unsubscribe from the server
Sourcepub async fn publish(
&self,
topic: String,
qos: QualityOfService,
payload: Vec<u8>,
) -> Result<(), IoError>
pub async fn publish( &self, topic: String, qos: QualityOfService, payload: Vec<u8>, ) -> Result<(), IoError>
Publish a message
Sourcepub async fn disconnect(&mut self, force: bool) -> Result<(), IoError>
pub async fn disconnect(&mut self, force: bool) -> Result<(), IoError>
Disconnect from the server
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Check if the client has been disconnected from the server, useful to check whether disconnection is completed
Trait Implementations§
Source§impl Clone for MqttClient
impl Clone for MqttClient
Source§fn clone(&self) -> MqttClient
fn clone(&self) -> MqttClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more