Struct coap::client::CoAPClient

source ·
pub struct CoAPClient<T: ClientTransport> { /* private fields */ }

Implementations§

source§

impl CoAPClient<UdpTransport>

source

pub async fn new_with_specific_source<A: ToSocketAddrs, B: ToSocketAddrs>( bind_addr: A, peer_addr: B ) -> IoResult<Self>

source

pub async fn new_udp<A: ToSocketAddrs>(addr: A) -> IoResult<Self>

source

pub async fn send_all_coap( &self, request: &CoapRequest<SocketAddr>, segment: u8 ) -> IoResult<()>

Send a request to all CoAP devices.

  • IPv4 AllCoAP multicast address is ‘224.0.1.187’
  • IPv6 AllCoAp multicast addresses are ‘ff0?::fd’ Parameter segment is used with IPv6 to determine the first octet. It’s value can be between 0x0 and 0xf. To address multiple segments, you have to call send_all_coap for each of the segments.
source

pub fn set_broadcast(&self, value: bool) -> IoResult<()>

source

pub async fn create_receiver_for( &self, request: &CoapRequest<SocketAddr> ) -> MessageReceiver

creates a receiver based on a specific request this method can be used if you send a multicast request and expect multiple responses. only use this method if you know what you are doing


use coap_lite::{
    RequestType
};
use coap::request::RequestBuilder;
use coap::client::UdpCoAPClient;

async fn foo() {
  let segment = 0x0;
  let client = UdpCoAPClient::new_udp("127.0.0.1:5683")
         .await
         .unwrap();
  let request = RequestBuilder::new("test-echo", RequestType::Get)
      .data(Some(vec![0x51, 0x55, 0x77, 0xE8]))
      .confirmable(true)
      .build();

  let mut receiver = client.create_receiver_for(&request).await;
  client.send_all_coap(&request, segment).await.unwrap();
  loop {
     let recv_packet = receiver.receive().await.unwrap();
     assert_eq!(recv_packet.payload, b"test-echo".to_vec());
  }
}
source§

impl CoAPClient<DtlsConnection>

source

pub async fn from_udp_dtls_config(config: UdpDtlsConfig) -> IoResult<Self>

source§

impl<T: ClientTransport + 'static> CoAPClient<T>

source

pub fn from_transport(transport: T) -> Self

Create a CoAP client with a chosen transport type

source

pub async fn get(url: &str) -> IoResult<CoapResponse>

Execute a single get request with a coap url

source

pub async fn get_with_timeout( url: &str, timeout: Duration ) -> IoResult<CoapResponse>

Execute a single get request with a coap url and a specific timeout.

source

pub async fn post(url: &str, data: Vec<u8>) -> IoResult<CoapResponse>

Execute a single post request with a coap url using udp

source

pub async fn post_with_timeout( url: &str, data: Vec<u8>, timeout: Duration ) -> IoResult<CoapResponse>

Execute a single post request with a coap url using udp

source

pub async fn put(url: &str, data: Vec<u8>) -> IoResult<CoapResponse>

Execute a put request with a coap url using udp

source

pub async fn put_with_timeout( url: &str, data: Vec<u8>, timeout: Duration ) -> IoResult<CoapResponse>

Execute a single put request with a coap url using udp

source

pub async fn delete(url: &str) -> IoResult<CoapResponse>

Execute a single delete request with a coap url using udp

source

pub async fn delete_with_timeout( url: &str, timeout: Duration ) -> IoResult<CoapResponse>

Execute a single delete request with a coap url using udp

source

pub async fn request( url: &str, method: Method, data: Option<Vec<u8>> ) -> IoResult<CoapResponse>

Execute a single request (GET, POST, PUT, DELETE) with a coap url using udp

source

pub async fn request_with_timeout( url: &str, method: Method, data: Option<Vec<u8>>, timeout: Duration ) -> IoResult<CoapResponse>

Execute a single request (GET, POST, PUT, DELETE) with a coap url and a specfic timeout using udp

source

pub async fn send( &self, request: CoapRequest<SocketAddr> ) -> IoResult<CoapResponse>

Send a Request via the given transport, and receive a response. users are responsible for filling meaningful fields in the request this method supports blockwise requests

source

pub async fn observe<H: FnMut(Packet) + Send + 'static>( &self, resource_path: &str, handler: H ) -> IoResult<Sender<ObserveMessage>>
where T: 'static + Send + Sync,

source

pub async fn observe_with_timeout<H: FnMut(Packet) + Send + 'static>( &mut self, resource_path: &str, handler: H, timeout: Duration ) -> IoResult<Sender<ObserveMessage>>
where T: 'static + Send + Sync,

Observe a resource with the handler and specified timeout using the given transport. Use the oneshot sender to cancel observation. If this sender is dropped without explicitly cancelling it, the observation will continue forever.

source

pub async fn observe_with<H: FnMut(Packet) + Send + 'static>( &self, request: CoapRequest<SocketAddr>, handler: H ) -> IoResult<Sender<ObserveMessage>>

observe a resource with a given transport using your own request Use this method if you need to set some specific options in your requests. This method will add observe flags and a message id as a fallback Use this method if you plan on re-using the same client for requests

source

pub async fn send_single_request( &self, request: &CoapRequest<SocketAddr> ) -> IoResult<CoapResponse>

sends a request through the transport. If a request is confirmable, it will attempt retries until receiving a response. requests sent using a multicast-address should be non-confirmable the user is responsible for setting meaningful fields in the request Do not use this method unless you need low-level control over the protocol (e.g., multicast), instead use send for client applications.

source

pub fn set_receive_timeout(&mut self, dur: Duration)

Set the receive timeout.

source

pub fn set_transport_retries(&mut self, num_retries: usize)

source

pub fn set_block1_size(&mut self, block1_max_bytes: usize)

Set the maximum size for a block1 request. Default is 1024 bytes

Trait Implementations§

source§

impl<T: ClientTransport> Clone for CoAPClient<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CoAPClient<T>
where T: Sync + Send,

§

impl<T> !RefUnwindSafe for CoAPClient<T>

§

impl<T> Send for CoAPClient<T>
where T: Sync + Send,

§

impl<T> Sync for CoAPClient<T>
where T: Sync + Send,

§

impl<T> Unpin for CoAPClient<T>
where T: Sync + Send,

§

impl<T> !UnwindSafe for CoAPClient<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V