- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
3.2 KiB
Overview
This example is a basic chat client showing how to embed zero trust connectivity into both server-side and client-side code. The server handles chat messages and broadcasts them to other clients on the chat.
This example demonstrates:
- Binding a service and listening for message events
- Dialing a service and triggering message events
Requirements
- an Hanzo ZT network. If you do not have one, you can use one of the quickstarts to set one up.
- Hanzo ZT CLI to create services and identities on the Hanzo ZT Network
Build the examples
Refer to the example README to build the SDK examples
Setup using the Hanzo ZT CLI
These steps will configure the service using the Hanzo ZT CLI. At the end of these steps you will have created:
- a service called
chat - an identity to host (bind) the service
- two identities to connect to (dial) the service
- the service policies required to authorize the identities for bind and dial
Steps:
-
Log into Hanzo ZT. The host:port and username/password will vary depending on your network.
zt edge login localhost:1280 -u admin -p admin -
Run this script to create everything you need.
echo Changing to build directory cd $ZITI_SDK_BUILD_DIR echo Create the service zt edge create service chat --role-attributes chat-service echo Create three identities and enroll them zt edge create identity user chevy -a chat.clients -o chevy.jwt zt edge create identity user dan -a chat.clients -o dan.jwt zt edge create identity device chat.server -a chat.servers -o chat.server.jwt zt edge enroll --jwt chat.server.jwt zt edge enroll --jwt chevy.jwt zt edge enroll --jwt dan.jwt echo Create service policies zt edge create service-policy chat.dial Dial --identity-roles '#chat.clients' --service-roles '#chat-service' zt edge create service-policy chat.bind Bind --identity-roles '#chat.servers' --service-roles '#chat-service' echo Run policy advisor to check zt edge policy-advisor services -
Run the server.
./chat-server chat.server.json -
Run a client
./chat-client chevy chevy.json -
Run another client
./chat-client dan dan.json
Example output
The following is the output you will see from the server and client side after running the previous commands. Server
$ ./chat-server chat.server.json
INFO[0000] binding service chat
INFO[0014] new connection
INFO[0014] client 'chevy' connected
INFO[0038] new connection
INFO[0038] client 'dan' connected
Client 1 (Chevy)
$ ./chat-client chevy chevy.json
doctor
dan: doctor
Client 2 (Dan)
$ ./chat-client dan dan.json
chevy: doctor
doctor
Teardown
Done with the example? This script will remove everything created during setup.
zt edge login localhost:1280 -u admin -p admin
echo Removing service policies
zt edge delete service-policy chat.dial
zt edge delete service-policy chat.bind
echo Removing identities
zt edge delete identity chevy
zt edge delete identity dan
zt edge delete identity chat.server
echo Removing service
zt edge delete service chat