Zenoh Config
zenoh.Config() controls how a Zenoh session starts, discovers other Zenoh
nodes, opens network connections, and communicates.
In the simple examples, this is enough:
That means: use the default Zenoh configuration.
The default is useful for local demos because Zenoh can discover other peers automatically on the local network.
Discovery to communication flow
flowchart TD
A[Create zenoh.Config] --> B[Open Zenoh session]
B --> C[Choose mode<br/>peer, client, or router]
C --> D[Scout / discover other nodes]
D --> E[Connect to matching peers or routers]
E --> F[Exchange declarations<br/>publishers, subscribers, queryables]
F --> G[Match key expressions]
G --> H[Send data samples]
The flow:
- Your application creates a
zenoh.Config. zenoh.open(config)starts a Zenoh session.- Zenoh decides the session mode:
peer,client, orrouter. - Zenoh discovers or connects to other nodes.
- Nodes exchange declarations, such as publishers and subscribers.
- Zenoh matches key expressions.
- Published samples are delivered to subscribers.
Example:
The subscriber receives the data because demo/robot/counter matches
demo/robot/**.
Important configuration fields
Important fields to learn first:
mode: how this process participates in the Zenoh networkconnect/endpoints: remote endpoints this session should connect tolisten/endpoints: local endpoints this session should listen onscouting/multicast/enabled: enable or disable multicast discoveryscouting/multicast/address: multicast group used for discoveryscouting/multicast/interface: network interface used for discoverytransport/link/protocols: protocols allowed by the transport layertimestamping/enabled: attach timestamps to samples
Common modes:
| Mode | Meaning |
|---|---|
peer |
Talks directly with other peers or routers. Good for simple distributed systems. |
client |
Connects to a Zenoh router. Common when you want controlled routing. |
router |
Routes data between clients, peers, networks, or storage/plugins. |
Create config in Python
Start from default config:
Insert values:
Read values:
Create config from JSON5 text:
Open a session:
Default peer discovery
In peer mode, Zenoh can discover other peers using scouting.
The common local-network flow is:
Default multicast scouting uses the multicast address:
This is discovery traffic. It is not the same as the application data key, such
as demo/robot/counter.
Configure peer mode
Explicit peer config:
Use this when peers are on the same network and multicast discovery is allowed.
Disable discovery and connect manually
Sometimes multicast discovery is blocked by the network, container setup, VPN, or firewall.
In that case, disable multicast scouting and configure explicit endpoints.
Peer 1 listens on a UDP endpoint:
Peer 2 connects to that UDP endpoint:
The important part is the endpoint:
This tells Zenoh to use a UDP transport endpoint.
For two machines, replace 127.0.0.1 with the real IP address of the peer that
is listening.
Example:
Combined UDP peer demo
This demo starts both peers from one Python file.
Run:
Expected idea:
Discovery vs configured endpoints
Use discovery when:
- peers are on the same LAN
- multicast is allowed
- you want simple setup
Use configured endpoints when:
- multicast is blocked
- peers run in containers
- peers run across subnets
- you need deterministic topology
- you want to connect clients to a known router
Client and router idea
Peer-to-peer is simple, but larger systems often use a router.
Client config:
Router:
The client connects to the router. The router helps route data between clients, peers, storages, and plugins.
Practical notes
- Use
peermode for simple local experiments. - Use
clientmode when connecting to a known router. - Use explicit
connect/endpointswhen discovery does not work. - Use
listen/endpointswhen other nodes should connect to this process. - Use
tcp/...first if you need the simplest reliable setup. - Use
udp/...when you specifically want UDP transport behavior. - Check firewall rules when peers do not discover or connect.
- In containers, multicast discovery may not work unless networking is configured for it.