Publish and discover an application service

Expose one TCP service through Wendy Net and resolve it from a second application.

Guided walkthrough·Intermediate·5 min read
Requirements and learning goals

Before you start

  • Two devices with verified Wendy Net connectivity
  • Docker and Wendy CLI; the server and client are included in the download

You will be able to

  • Separate port publication from service advertisement
  • Use discovered addresses instead of hard-coded device identities

Service discovery lets a dashboard find an API after its address changes. Publishing a port permits connections; advertising the service tells clients where to connect. This exercise does both.

For a remote camera rather than an application endpoint, use the SensorLink pairing workflow and verify changing observations after connection.

Publish a server

Use an HTTP app listening on 0.0.0.0:8080. The download includes this network configuration:

{
  "appId": "com.example.learn-api",
  "platform": "linux",
  "isolation": "isolated",
  "entitlements": [{
    "type": "network",
    "mode": "mesh",
    "serviceCIDR": "10.99.0.0/16",
    "ports": [{ "host": 18080, "container": 8080, "protocol": "tcp" }]
  }]
}

Deploy both apps after the steps below.

What serviceCIDR means

serviceCIDR identifies the virtual IP range for mesh services. Connections to these addresses route to publishing apps.

CIDR describes an address block. /16 fixes the first 16 bits: 10.99.0.0/16 spans 10.99.0.0 through 10.99.255.255.

Use 10.99.0.0/16 on both apps, the currently supported range. It does not change LAN or addresses. Do not substitute your Wi-Fi subnet or invent a service address.

serviceCIDR alone does not publish or advertise anything. Discovery supplies the endpoint to use.

Checkpoint 1 of 3

The mesh service range is 10.99.0.0/16. Which address could a discovered mesh service have?

Commit to an answer. Every choice explains itself.

Add mDNS to the app

mDNS finds local services without a central DNS server. DNS-SD describes their name, type, address, port, and TXT metadata. The Python zeroconf library handles those records for you.

Download the complete server and client. Each directory includes a Dockerfile, pinned dependency, and wendy.json. No conversion is needed.

The server listens on 0.0.0.0:8080. Its core announcement is:

info = ServiceInfo(
    "_http._tcp.local.",
    f"{instance}._http._tcp.local.",
    addresses=[socket.inet_aton(address)],
    port=8080,
    properties={"demo": "learn-mesh", "path": "/"},
    server=f"{hostname}.local.",
)
zc.register_service(info, allow_name_change=True)

Here address is the container's private eth0 IPv4 address, not a LAN or mesh address. The complete example reads it automatically and binds discovery to that interface. Advertise container port 8080; remote clients receive published port 18080. Keep the process running, and unregister the service on shutdown.

Checkpoint 2 of 3

The server registers port=8080, and wendy.json maps host port 18080 to container port 8080. Which port is in the endpoint that a client on the other device discovers?

Commit to an answer. Every choice explains itself.

Discover and call it

The client uses ServiceBrowser to find _http._tcp.local. instances. A callback queues discoveries; the main thread resolves them and makes HTTP requests:

info = zc.get_service_info(service_type, name, timeout=2000)
if info and info.properties.get(b"demo") == b"learn-mesh":
    address = info.parsed_addresses(IPVersion.V4Only)[0]
    url = f"http://{address}:{info.port}/"

Use that resolved URL, including its port. The TXT marker selects this demo; it is not authentication. The complete client checks for addresses, bounds requests, and exits after a successful response or a discovery timeout.

Unzip the download, then deploy:

cd mesh-mdns/publisher
wendy run --detach
cd ../client
wendy run

Select the publishing device first, then the other device for the client. Expect a discovered 10.99.x.x:18080 endpoint and JSON containing instance and status: "ok". The client exits after one successful request; rerun it after restarting the publisher to check recovery.

Check the expected result

The client should print the discovered endpoint and the publisher's JSON, then exit successfully. Restart the publisher and rerun the client. The response should identify the new publisher instance. A discovery announcement without a successful HTTP response is incomplete.

Checkpoint 3 of 3

The client finds the publisher, but its HTTP request to the discovered endpoint times out. Where does the exercise stand?

Commit to an answer. Every choice explains itself.

Troubleshooting

The port mapping does not announce the service. An announcement does not grant an undeclared port. A server bound only to loopback will not work through its container interface.

TXT values are preserved, so embedded private URLs may be unreachable. Use the resolved endpoint. This example opens its own mDNS socket: no Avahi or UDP 5353 port mapping is needed. The agent carries discovery records between devices.

No result? Check mesh peers, publisher logs, and the app's private interface. Stop the publisher app when finished.

Source: Service sharing and discovery.

API reference: python-zeroconf.

Can you do each of these?

  • Separate port publication from service advertisement
  • Use discovered addresses instead of hard-coded device identities

0 of 3 checkpoints solved. Try checkpoint 1

Previous: Connect nearby devices with Wendy Net
All lessons in this topic
  1. 1. Connect nearby devices with Wendy Net
  2. 2. Publish and discover an application service
  3. 3. Pair a SensorLink source
  4. 4. Use one camera workflow across devices and robots

Ask Wendy

Answers about Wendy and WendyOS

What would you like to know?

Ask about devices, development, and deployment.

Check linked docs for technical details.