Echo Server Sample
The Echo Server sample demonstrates a minimal server running inside an Atym container that simply echoes back any input it receives. This is a classic example for testing connectivity and basic I/O.
Building the Container
Building the Echo Server sample involves three main steps: compiling the application to WebAssembly, packaging it into an Atym container, and pushing it to the Atym Hub.
Building the Application
Navigate to the echo-server sample in the Ocre SDK samples directory and create a build directory to compile the application to WebAssembly:
cd ocre-sdk/generic/echo-server/
mkdir build && cd build
cmake ..
make
This creates a WASM module named echo-server.wasm, that will be used by the atym build command in the next step.
Create the Container
Return to the project root directory and build the Atym container:
cd ..
atym build
If the container creation was successful, you should see a new directory, (.atym) in your home directory (~/.atym). In there, you will find a directory with the container image's name and the container contents. In our case, the directory is echo-server, as that is the container image name defined in our build.yaml file in the project root.
Push the Container to the Atym Hub
Push your container to the Atym Hub:
atym push echo-server
We did not specify a "tag" (e.g. atym push echo-server:tag), which will result in this image being tagged as latest.
Deploying the Container
This section shows you how to deploy the Echo Server sample container to your device using the Atym CLI.
This example uses deviceName for device identification, which is typically easier to remember and use. You can also use deviceUUID if preferred. To find your device name or UUID, use atym list devices or check the Atym Hub web interface.
Deploy to the Target Device
Deploy the container to your device with the following command, replacing deviceName with your device's name:
atym run echo-server echo-server -n deviceName
Where the first echo-server is your chosen container name, and the next echo-server is the IMAGE_REF[:TAG], which is the container image from your registry. In this example we did not specify a tag, and are therefore running the latest tag. This command also requires a device identifier ( -n for deviceName, or -d for deviceUUID).
Verify Deployment
The Atym Hub will deploy your container to the device. You should see output in your console indicating the Echo Server is running and ready to accept connections, similar to the following:
**********************************************
Echo server starting...
Echo server listening on port 8000
**********************************************
To connect:
1. Find this device's IP: net iface
2. Telnet to the device: telnet <IP> 8000
3. Type messages to test the echo server!
**********************************************
Next Steps
After you've mastered the Echo Server, try the WebSocket Server Sample to learn how to build and deploy a web server using Mongoose under the hood. This next guide will introduce you to handling HTTP and WebSocket connections.