Struct zenoh::net::Session[][src]

pub struct Session { /* fields omitted */ }
Expand description

A zenoh-net session.

Implementations

Returns the identifier for this session.

Close the zenoh-net Session.

Sessions are automatically closed when dropped, but you may want to use this function to handle errors or close the Session asynchronously.

Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
session.close().await.unwrap();

Get informations about the zenoh-net Session.

Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let info = session.info();

Associate a numerical Id with the given resource key.

This numerical Id will be used on the network to save bandwidth and ease the retrieval of the concerned resource in the routing tables.

Arguments
  • resource - The resource key to map to a numerical Id
Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let rid = session.declare_resource(&"/resource/name".into()).await.unwrap();

Undeclare the numerical Id/resource key association previously declared with declare_resource.

Arguments
  • rid - The numerical Id to unmap
Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let rid = session.declare_resource(&"/resource/name".into()).await.unwrap();
session.undeclare_resource(rid).await;

Declare a Publisher for the given resource key.

Written resources that match the given key will only be sent on the network if matching subscribers exist in the system.

Arguments
  • resource - The resource key to publish
Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let publisher = session.declare_publisher(&"/resource/name".into()).await.unwrap();
session.write(&"/resource/name".into(), "value".as_bytes().into()).await.unwrap();

Declare a Subscriber for the given resource key.

Arguments
  • resource - The resource key to subscribe
  • info - The SubInfo to configure the subscription
Examples
use zenoh::net::*;
use futures::prelude::*;

let session = open(config::peer()).await.unwrap();
let sub_info = SubInfo {
    reliability: Reliability::Reliable,
    mode: SubMode::Push,
    period: None
};
let mut subscriber = session.declare_subscriber(&"/resource/name".into(), &sub_info).await.unwrap();
while let Some(sample) = subscriber.receiver().next().await {
    println!("Received : {:?}", sample);
}

Declare a CallbackSubscriber for the given resource key.

Arguments
  • resource - The resource key to subscribe
  • info - The SubInfo to configure the subscription
  • data_handler - The callback that will be called on each data reception
Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let sub_info = SubInfo {
    reliability: Reliability::Reliable,
    mode: SubMode::Push,
    period: None
};
let subscriber = session.declare_callback_subscriber(&"/resource/name".into(), &sub_info,
    |sample| { println!("Received : {} {}", sample.res_name, sample.payload); }
).await.unwrap();

This is an experimental API.

Declare a Queryable for the given resource key.

Arguments
Examples
use zenoh::net::*;
use zenoh::net::queryable::EVAL;
use futures::prelude::*;

let session = open(config::peer()).await.unwrap();
let mut queryable = session.declare_queryable(&"/resource/name".into(), EVAL).await.unwrap();
while let Some(query) = queryable.receiver().next().await {
    query.reply_async(Sample{
        res_name: "/resource/name".to_string(),
        payload: "value".as_bytes().into(),
        data_info: None,
    }).await;
}

Write data.

Arguments
  • resource - The resource key to write
  • payload - The value to write
Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
session.write(&"/resource/name".into(), "value".as_bytes().into()).await.unwrap();

Write data with options.

Arguments
  • resource - The resource key to write
  • payload - The value to write
  • encoding - The encoding of the value
  • kind - The kind of value
  • congestion_control - The value for the congestion control
Examples
use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
session.write_ext(&"/resource/name".into(), "value".as_bytes().into(), encoding::TEXT_PLAIN, data_kind::PUT, CongestionControl::Drop).await.unwrap();

Query data from the matching queryables in the system.

Arguments
  • resource - The resource key to query
  • predicate - An indication to matching queryables about the queried data
  • target - The kind of queryables that should be target of this query
  • consolidation - The kind of consolidation that should be applied on replies
Examples
use zenoh::net::*;
use futures::prelude::*;

let session = open(config::peer()).await.unwrap();
let mut replies = session.query(
    &"/resource/name".into(),
    "predicate",
    QueryTarget::default(),
    QueryConsolidation::default()
).await.unwrap();
while let Some(reply) = replies.next().await {
    println!(">> Received {:?}", reply.data);
}

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Performs the conversion.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more