Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pojiro committed Jan 30, 2024
1 parent 1113c11 commit 56ac8dd
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

Zenohex is the [zenoh](https://zenoh.io/) client library for elixir.

Currently zenohex uses version 0.10.1-rc of zenoh.
If you want to communicate with Rust version of Zenoh, please use the same version.
**Currently zenohex uses version 0.10.1-rc of zenoh.**
**If you want to communicate with Rust version of Zenoh, please use the same version.**

## Installation

Expand All @@ -27,40 +27,36 @@ and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/zenohex>.

### Install rust (Optional)

Since version 0.1.3, Zenohex uses rustler precompiled and does not require Rust to be installed.

If you need to build rust NIFs code, please set the environment variable and install rust.
```
export RUSTLER_PRECOMPILATION_EXAMPLE_BUILD=1
If you want to build rust NIFs code, please add following to your config file.

```elixir
config :rustler_precompiled, :force_build, zenohex: true
```

https://www.rust-lang.org/tools/install

## Getting Started

### Publisher example
#### terminal 1 (Subscriber)
```
iex -S mix
iex> NifZenoh.tester_sub "demo/example/zenoh-rs-pub"
```
### Pub/Sub example

#### terminal 2 (Publisher)
```
iex -S mix
iex> session = Zenohex.open
iex> {:ok, publisher} = Session.declare_publisher(session, "demo/example/zenoh-rs-pub")
iex> Publisher.put(publisher, "Hello zenoh?")
```sh
$ iex -S mix
```

### Subscriber example
```
(Subscriber)
iex -S mix
iex> session = Zenohex.open
iex> Session.declare_subscriber(session, "demo/example/zenoh-rs-pub", fn m -> IO.inspect(m) end)
(third argument is callback function)
(Publisher)
iex> {:ok, publisher} = Session.declare_publisher(session, "demo/example/zenoh-rs-pub")
iex> Publisher.put(publisher, "Hello zenoh?")
```elixir
iex(1)> session = Zenohex.open!()
#Reference<>
iex(2)> publisher = Zenohex.Session.declare_publisher!(session, "pub/sub")
#Reference<>
iex(3)> subscriber = Zenohex.Session.declare_subscriber!(session, "pub/sub")
#Reference<>
iex(4)> Zenohex.Publisher.put!(publisher, "Hello Zenoh Dragon")
:ok
iex(5)> Zenohex.Subscriber.recv_timeout!(subscriber, 1000)
"Hello Zenoh Dragon"
iex(6)> Zenohex.Subscriber.recv_timeout!(subscriber, 1000)
:timeout
```

0 comments on commit 56ac8dd

Please sign in to comment.