Score
0
Watch 1 Star 2 Fork 0

LazyDog / sctpxRustMIT

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

sctpx

Coding with SCTP protocol.

Example

use sctpx::{client, server};
use myutil::{err::*, *};
use std::{sync::Arc, thread, time::Duration};

const ADDR: &str = "127.0.0.1:9999";

fn main() {
    thread::spawn(|| {
        let cb = |recvd: &[u8],
                  hdr: Arc<server::Hdr>,
                  peer: server::PeerAddr|
         -> Result<()> {
            assert_eq!(b"ABC", recvd);
            hdr
                .sendto(b"DEF", &peer)
                .map(|n| assert_eq!(n, 3)).c(d!())
        };
        pnk!(server::start_server(ADDR, None, cb, false));
    });

    // wait server to start
    thread::sleep(Duration::from_secs(1));

    let cli = pnk!(client::Hdr::new());
    assert_eq!(3, pnk!(cli.sendto_straddr(b"ABC", ADDR)));

    let buf = &mut [0; 8];
    let res = pnk!(cli.recvfrom(buf));
    assert_eq!(b"DEF", &buf[0..res.0]);
    assert_eq!(res.0, 3);
    assert_eq!(pnk!(res.1).to_string().as_str(), ADDR);
}

Comments ( 0 )

Sign in for post a comment

About

自研的 Rust 三方库,crates.io 上使用量 13,000+ spread retract
Cancel

Releases

No release

Gitee Metrics

Contributors

All

Activities

load more
can not load any more