3 个版本

0.1.3 2024年4月20日
0.1.2 2024年3月28日
0.1.1 2024年3月27日
0.1.0 2024年3月2日

#1041 in 网络编程

MIT/Apache

475KB
11K SLoC

Rusmpp

Rust 实现 SMPP v5 协议。

use futures::{SinkExt, StreamExt};
use rusmpp::{
    codec::command_codec::CommandCodec,
    commands::{
        command::Command,
        pdu::Pdu,
        types::{command_id::CommandId, command_status::CommandStatus},
    },
};
use tokio::net::TcpStream;
use tokio_util::codec::{FramedRead, FramedWrite};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let stream = TcpStream::connect("34.242.18.250:2775").await?;

    let (reader, writer) = stream.into_split();
    let mut framed_read = FramedRead::new(reader, CommandCodec {});
    let mut framed_write = FramedWrite::new(writer, CommandCodec {});

    let enquire_link_command = Command::new(CommandStatus::EsmeRok, 0, Pdu::EnquireLink);

    // Send commands.
    framed_write.send(&enquire_link_command).await?;

    // Wait for responses.
    while let Some(Ok(command)) = framed_read.next().await {
        if let CommandId::EnquireLinkResp = command.command_id() {
            break;
        }
    }

    Ok(())
}

查看 examples 目录获取更多示例。

许可证

许可协议为以下之一:

贡献

除非你明确声明,否则根据 Apache-2.0 许可证定义的,任何有意提交以包含在本作品中的贡献,都应如上所述双重许可,不附加任何额外的条款或条件。

依赖项

~0–1.3MB
~22K SLoC