Expand description
§Rusmppc
§Features
rustls: Enables TLS support viarustls. Enabled by default.rustls-tls-native-roots: Uses the platform’s native root certificates throughrustls-native-certswhile using default configuration. Enables therustlsfeature and is enabled by default.rustls-tls-webpki-roots: Uses thewebpki-rootscrate’s root certificates while using default configuration. Enables therustlsfeature and is enabled by default.rustls-aws-lc-rs: Usesaws-lc-rsas the TLS backend forrustls. Enabled by default.rustls-ring: Usesringas the TLS backend forrustls.native-tls: Enables TLS support vianative-tls.
§Example
use std::{str::FromStr, time::Duration};
use futures::StreamExt;
use rusmpp::{
CommandId,
pdus::{BindTransceiver, DeliverSmResp, SubmitSm},
types::{COctetString, OctetString},
values::{EsmClass, Npi, RegisteredDelivery, ServiceType, Ton},
};
use rusmppc::{ConnectionBuilder, Event};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (client, mut events) = ConnectionBuilder::new()
// Set the maximum command length for incoming commands.
.max_command_length(1024)
// Every 5 seconds send an enquire link command to the server.
.enquire_link_interval(Duration::from_secs(5))
// If the server did not respond within 3 seconds, close the connection.
.enquire_link_response_timeout(Duration::from_secs(3))
// If the server does not respond within 2 seconds, consider it a timeout.
// The operation is assumed to have failed.
.response_timeout(Duration::from_secs(2))
.connect("smpp://127.0.0.1:2775")
.await?;
// Bind the client as a transceiver.
client
.bind_transceiver(
BindTransceiver::builder()
.system_id(COctetString::from_str("NfDfddEKVI0NCxO")?)
.password(COctetString::from_str("rEZYMq5j")?)
.system_type(COctetString::empty())
.addr_ton(Ton::Unknown)
.addr_npi(Npi::Unknown)
.address_range(COctetString::empty())
.build(),
)
.await?;
let events = tokio::spawn(async move {
// Listen for events like incoming commands and background errors.
while let Some(event) = events.next().await {
println!("Event: {:?}", event);
}
});
// Send commands to the server and wait for the responses.
let response = client
.submit_sm(
SubmitSm::builder()
.service_type(ServiceType::default())
.source_addr_ton(Ton::Unknown)
.source_addr_npi(Npi::Unknown)
.source_addr(COctetString::from_str("12345")?)
.destination_addr(COctetString::from_str("491701234567")?)
.esm_class(EsmClass::default())
.registered_delivery(RegisteredDelivery::request_all())
.short_message(OctetString::from_str("Hi, I am a short message.")?)
.build(),
)
.await?;
println!("SubmitSm response: {:?}", response);
// Send an unbind command to the server and wait for the response.
client.unbind().await?;
// Close the connection.
client.close().await?;
// Wait for the connection to be closed.
client.closed().await;
// When the connection is closed, the event stream will also be closed.
events.await?;
Ok(())
}Modules§
- error
SMPPclient error type.
Structs§
- Client
SMPPClient.- Connection
Builder - Builder for creating a new
SMPPconnection.
Enums§
- Event
SMPPevent.