|
| 1 | +# Overview |
| 2 | +This example illustrates how to send data to, and receive data from a UDP server via OpenZiti. |
| 3 | +You will configure an OpenZiti overlay network and run a UDP server that will respond with whatever text it was sent. |
| 4 | +The response from the server will be read written to the console. |
| 5 | + |
| 6 | +This example demonstrates a hybrid approach ZTAA --> ZTHA: |
| 7 | +* Dialing a service |
| 8 | +* Binding a service using a tunneler |
| 9 | + |
| 10 | +## Requirements |
| 11 | +* OpenZiti CLI to create services and identities on the OpenZiti Network |
| 12 | +* an OpenZiti network. If you have one you'd like to use, great. The guide is written using the |
| 13 | + `ziti edge quickstart` command. |
| 14 | +* All commands are executed relative to the `example` folder |
| 15 | + |
| 16 | +## Build the examples |
| 17 | +Refer to the [example README](../README.md) to build the SDK examples |
| 18 | + |
| 19 | +## Run and Configure OpenZiti |
| 20 | +The README assumes the `ziti` CLI on your path. If not, supply the full path to the `ziti` executable. This command |
| 21 | +will start a ziti overlay network on ports 1280/3022 for use with the rest of the README. The default values will |
| 22 | +also be used for username and password. The router from the quickstart is the identity which will offload the OpenZiti |
| 23 | +traffic toward the UDP server |
| 24 | + |
| 25 | +In a new terminal run the following command: |
| 26 | +``` |
| 27 | +ziti edge quickstart |
| 28 | +``` |
| 29 | + |
| 30 | +To configure the overlay, you will need another terminal with `ziti` on the path. Now, add a service for the UDP |
| 31 | +server to be offloaded from the OpenZiti overlay as well as create the identity this example will use: |
| 32 | +``` |
| 33 | +svc_name="udp.relay.example" |
| 34 | +edge_router_name="quickstart-router" |
| 35 | +ziti edge login localhost:1280 -u admin -p admin -y |
| 36 | +ziti edge create config ${svc_name}.hostv1 host.v1 '{"protocol":"udp", "address":"127.0.0.1","port":10001}' |
| 37 | +ziti edge create service ${svc_name} --configs "${svc_name}.hostv1" |
| 38 | +ziti edge create service-policy ${svc_name}.dial Dial --identity-roles "#${svc_name}.dialers" --service-roles "@${svc_name}" |
| 39 | +ziti edge create service-policy ${svc_name}.bind Bind --identity-roles "#${svc_name}.binders" --service-roles "@${svc_name}" |
| 40 | +
|
| 41 | +ziti edge create identity ${svc_name}.client -a ${svc_name}.dialers -o ${svc_name}.client.jwt |
| 42 | +ziti edge enroll --jwt ${svc_name}.client.jwt |
| 43 | +
|
| 44 | +ziti edge update identity ${edge_router_name} -a "${svc_name}.binders" |
| 45 | +ziti edge policy-advisor services -q |
| 46 | +``` |
| 47 | + |
| 48 | +## Run the UDP Server |
| 49 | +In the terminal from where you configured the OpenZiti overlay start the UDP server. Make sure you're in the |
| 50 | +`example` folder and run: |
| 51 | +``` |
| 52 | +./build/udp-server |
| 53 | +``` |
| 54 | + |
| 55 | +You should now have a UDP server that is listening on port 10001 and will respond to UDP messages sent to it. |
| 56 | +``` |
| 57 | +$ ./build/udp-server |
| 58 | +Listening on :10001 |
| 59 | +``` |
| 60 | + |
| 61 | +## Run the Example |
| 62 | +Make sure the router (or identity) hosting the service establishes a terminator. Issue the following command and verify |
| 63 | +a terminator is listed as shown: |
| 64 | +``` |
| 65 | +ziti edge list terminators 'service.name="udp.relay.example"' |
| 66 | +``` |
| 67 | + |
| 68 | +example output: |
| 69 | +``` |
| 70 | +$ ziti edge list terminators 'service.name="udp.relay.example"' |
| 71 | +╭───────────────────────┬───────────────────┬───────────────────┬─────────┬───────────────────────┬──────────┬──────┬────────────┬──────────────╮ |
| 72 | +│ ID │ SERVICE │ ROUTER │ BINDING │ ADDRESS │ IDENTITY │ COST │ PRECEDENCE │ DYNAMIC COST │ |
| 73 | +├───────────────────────┼───────────────────┼───────────────────┼─────────┼───────────────────────┼──────────┼──────┼────────────┼──────────────┤ |
| 74 | +│ sNVBPDKuI6q5I0f2PrEc6 │ udp.relay.example │ quickstart-router │ tunnel │ sNVBPDKuI6q5I0f2PrEc6 │ │ 0 │ default │ 0 │ |
| 75 | +╰───────────────────────┴───────────────────┴───────────────────┴─────────┴───────────────────────┴──────────┴──────┴────────────┴──────────────╯ |
| 76 | +results: 1-1 of 1 |
| 77 | +``` |
| 78 | + |
| 79 | +With the terminator in place, run the sample |
| 80 | +``` |
| 81 | +./build/udp-offload-client ./udp.relay.example.client.json |
| 82 | +``` |
| 83 | + |
| 84 | +example output: |
| 85 | +``` |
| 86 | +$ ./build/udp-offload-client ./udp.relay.example.client.json |
| 87 | +INFO[0000] found service named: udp.relay.example |
| 88 | +INFO[0000] Connected to udp.relay.example successfully. |
| 89 | +INFO[0000] You may now type a line to be sent to the server (press enter to send) |
| 90 | +INFO[0000] The line will be sent to the reflect server and returned |
| 91 | +this is the udp example |
| 92 | +wrote 24 bytes |
| 93 | +Sent :this is the udp example |
| 94 | +Received: udp server echo: this is the udp example |
| 95 | +``` |
0 commit comments