pub struct ChannelProtocol { /* fields omitted */ }
Channel protocol structure
Create a new channel protocol instance using an automatically assigned UDP socket
- host_ip - The local IP address
- remote_addr - The remote IP and port to communicate with
- data_len - Max payload length
If this function encounters any errors, it will panic
use channel_protocol::*;
let channel_protocol = ChannelProtocol::new("0.0.0.0", "192.168.0.1:7000", 4096);
Set new remote address on existing channel procotol structure
- remote - New remote address
Send CBOR packet to the destination port
- vec - CBOR packet to send
If this function encounters any errors, it will return an error message string
extern crate channel_protocol;
extern crate serde_cbor;
use channel_protocol::*;
use serde_cbor::ser;
let c_protocol = ChannelProtocol::new("0.0.0.0", "0.0.0.0:7000", 4096);
let message = ser::to_vec_packed(&"ping").unwrap();
c_protocol.send(&message);
Receive a raw cbor message message
- timeout - Maximum time to wait for a reply. If
None
, will block indefinitely
- If this function times out, it will return
Err(ProtocolError::ReceiveTimeout)
- If this function encounters any errors, it will return an error message string
extern crate channel_protocol;
use channel_protocol::*;
use std::time::Duration;
let c_protocol = ChannelProtocol::new("0.0.0.0", "0.0.0.0:7000", 4096);
let message = match c_protocol.recv_raw(Some(Duration::from_secs(1))) {
Ok(data) => data,
Err(ProtocolError::ReceiveTimeout) => {
println!("Timeout waiting for message");
return;
}
Err(err) => panic!("Failed to receive message: {}", err),
};
Receive a parsed channel procotol message
- timeout - Maximum time to wait for a reply. If
None
, will block indefinitely
- If this function times out, it will return
Err(ProtocolError::ReceiveTimeout)
- If this function encounters any errors, it will return an error message string
extern crate channel_protocol;
use channel_protocol::*;
use std::time::Duration;
let c_protocol = ChannelProtocol::new("0.0.0.0", "0.0.0.0:7000", 4096);
let message = match c_protocol.recv_message(Some(Duration::from_secs(1))) {
Ok(data) => data,
Err(ProtocolError::ReceiveTimeout) => {
println!("Timeout waiting for message");
return;
}
Err(err) => panic!("Failed to receive message: {}", err),
};
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static