[−][src]Struct channel_protocol::ChannelProtocol
Channel protocol structure
Methods
impl Protocol
[src]
[−]
impl Protocol
pub fn new(host_ip: &str, remote_addr: &str, data_len: u32) -> Self
[src]
[−]
pub fn new(host_ip: &str, remote_addr: &str, data_len: u32) -> Self
Create a new channel protocol instance using an automatically assigned UDP socket
Arguments
- host_ip - The local IP address
- remote_addr - The remote IP and port to communicate with
- data_len - Max payload length
Errors
If this function encounters any errors, it will panic
Examples
use channel_protocol::*; let channel_protocol = ChannelProtocol::new("0.0.0.0", "192.168.0.1:7000", 4096);
pub fn set_remote(&mut self, remote: SocketAddr)
[src]
[−]
pub fn set_remote(&mut self, remote: SocketAddr)
pub fn send(&self, vec: &[u8]) -> Result<(), ProtocolError>
[src]
[−]
pub fn send(&self, vec: &[u8]) -> Result<(), ProtocolError>
Send CBOR packet to the destination port
Arguments
- vec - CBOR packet to send
Errors
If this function encounters any errors, it will return an error message string
Examples
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);
pub fn recv_raw(
&self,
timeout: Option<Duration>
) -> Result<Value, ProtocolError>
[src]
[−]
pub fn recv_raw(
&self,
timeout: Option<Duration>
) -> Result<Value, ProtocolError>
Receive a raw cbor message message
Arguments
- timeout - Maximum time to wait for a reply. If
None
, will block indefinitely
Errors
- If this function times out, it will return
Err(ProtocolError::ReceiveTimeout)
- If this function encounters any errors, it will return an error message string
Examples
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), };
pub fn recv_message(
&self,
timeout: Option<Duration>
) -> Result<Message, ProtocolError>
[src]
[−]
pub fn recv_message(
&self,
timeout: Option<Duration>
) -> Result<Message, ProtocolError>
Receive a parsed channel procotol message
Arguments
- timeout - Maximum time to wait for a reply. If
None
, will block indefinitely
Errors
- If this function times out, it will return
Err(ProtocolError::ReceiveTimeout)
- If this function encounters any errors, it will return an error message string
Examples
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), };
Auto Trait Implementations
impl Send for ChannelProtocol
impl Send for ChannelProtocol
impl !Sync for ChannelProtocol
impl !Sync for ChannelProtocol
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
[−]
impl<T, U> Into for T where
U: From<T>,
impl<T> From for T
[src]
[−]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
[−]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
[−]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T> Borrow for T where
T: ?Sized,
[src]
[−]
impl<T> Borrow for T where
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
[−]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
[−]
fn get_type_id(&self) -> TypeId
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
[−]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
[−]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T> BorrowMut for T where
T: ?Sized,
[src]
[−]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
[−]
fn borrow_mut(&mut self) -> &mut T