A simple echo server written in Rust.
Its basic use-case is for testing network connectivity in various scenario's. To this end, the project supports two modes:
- In normal mode, the
simple-echo-server
executable listens for TCP connections and echoes the byte stream - In HTTP mode, the
simple-echo-server
executable listens for incoming HTTP requests and echoes the bodies of the requests.
In addition, the project includes files to run the executable in Docker and Kubernetes.
Note that a precompiled version of the executable is available in the releases page and on Docker Hub.
To run 'bare metal', make sure you install the following:
- Rust 1.51 or later (see https://rustup.rs)
- Cargo (https://cratio.io; installed if you use rustup)
To run in Docker in Kubernetes, however, you only need those technologies.
Compilation is only necessary if you don't want to use the prebuilt binary/image.
First, clone the repository:
git clone https://github.com/Lut99/simple-echo-server && cd simple-echo-server
Next, you can build the project in the (default) TCP mode by using cargo
:
cargo build --release
which will generate the executable in ./target/release/simple-echo-server
.
Alternatively, to build in HTTP mode, specify the http
feature:
cargo build --release --features http
which will generate the same executable, ./target/release/simple-echo-server
.
To build the Docker image, run the following the root of the repository:
docker build -f ./docker/Dockerfile -t simple-echo-server:latest .
Possibly, if you have the Buildx plugin installed, you may need to specify the --load
flag to load the image in your daemon:
docker build --load -f ./docker/Dockerfile -t simple-echo-server:latest .
To run the bare metal version, run the following command:
./target/release/simple-echo-server
Run with the --help
flag to see other options.
To run with Docker, simply run:
docker run -d --rm --public 80:<PORT> simple-echo-server:latest <PORT>
Or, on Kubernetes:
kubectl apply -f ./k8s/deployment.yaml ./k8s/service.yaml
(To change the port, change the value of nodePort
in ./k8s/service.yaml
).
Once running, you can connect to it by using telnet
for the TCP case, or curl
for the HTTP case. For example:
# TCP case
telnet localhost <PORT>
(You can type and see the echoes, when done, hit Ctrl+], then type 'q' and hit enter)
# HTTP case, echo
curl -X GET localhost:<PORT> -d "Hello there\n"
# HTTP case, health
curl -X GET localhost:<PORT>/health
If you want to contribute anything to this project, welcome! Feel free to checkout the issues to find anything that needs doing, or create an issue yourself. You can also create pull requests if you're eager and already implemented something.
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.