docs(multiplexer): tidy up examples
This commit is contained in:
parent
87c423a22b
commit
fec280728b
3 changed files with 30 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use std::{os::unix::net::UnixListener, thread, time::Duration};
|
||||
use std::{net::TcpListener, thread, time::Duration};
|
||||
|
||||
use log::info;
|
||||
use pallas_multiplexer::{Channel, Multiplexer};
|
||||
|
||||
const PROTOCOLS: [u16; 2] = [0x8002u16, 0x8003u16];
|
||||
|
|
@ -7,8 +8,9 @@ const PROTOCOLS: [u16; 2] = [0x8002u16, 0x8003u16];
|
|||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
//let server = TcpListener::bind("0.0.0.0:3001").unwrap();
|
||||
let server = UnixListener::bind("/tmp/pallas").unwrap();
|
||||
let server = TcpListener::bind("0.0.0.0:3001").unwrap();
|
||||
|
||||
info!("listening for connections on port 3001");
|
||||
let (bearer, _) = server.accept().unwrap();
|
||||
|
||||
let mut muxer = Multiplexer::setup(bearer, &PROTOCOLS).unwrap();
|
||||
|
|
@ -17,11 +19,13 @@ fn main() {
|
|||
let handle = muxer.use_channel(protocol);
|
||||
|
||||
thread::spawn(move || {
|
||||
info!("starting thread for protocol: {}", protocol);
|
||||
|
||||
let Channel(_, rx) = handle;
|
||||
|
||||
loop {
|
||||
let payload = rx.recv().unwrap();
|
||||
println!("id:{}, length:{}", protocol, payload.len());
|
||||
info!("got message within thread, id:{}, length:{}", protocol, payload.len());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use std::{os::unix::net::UnixStream, thread, time::Duration};
|
||||
use std::{net::TcpStream, thread, time::Duration};
|
||||
|
||||
use log::info;
|
||||
use pallas_multiplexer::{Channel, Multiplexer};
|
||||
|
||||
const PROTOCOLS: [u16; 2] = [0x0002u16, 0x0003u16];
|
||||
|
|
@ -7,8 +8,8 @@ const PROTOCOLS: [u16; 2] = [0x0002u16, 0x0003u16];
|
|||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
//let bearer = TcpStream::connect("127.0.0.1:3001").unwrap();
|
||||
let bearer = UnixStream::connect("/tmp/pallas").unwrap();
|
||||
info!("connecting to tcp socket on 127.0.0.1:3001");
|
||||
let bearer = TcpStream::connect("127.0.0.1:3001").unwrap();
|
||||
let mut muxer = Multiplexer::setup(bearer, &PROTOCOLS).unwrap();
|
||||
|
||||
for protocol in PROTOCOLS {
|
||||
|
|
@ -19,8 +20,9 @@ fn main() {
|
|||
|
||||
loop {
|
||||
let payload = vec![1; 65545];
|
||||
info!("sending dumb payload for protocol: {}", protocol);
|
||||
tx.send(payload).unwrap();
|
||||
thread::sleep(Duration::from_millis(50u64 + (protocol as u64 * 10u64)));
|
||||
thread::sleep(Duration::from_millis(500u64 + (protocol as u64 * 10u64)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue