Rust TCP communication over protobuf protocol.
This repo contains three seperate code bases:
- Client
- Server
- Proto for common proto files among server and client
To clone the repo and required submodules:
git clone --recurse-submodules https://github.com/AktugHakan/rust-protobuf-networking.git
If you cloned the repo without --recurse-modules
flag, you can get the submodule using:
git submodule init
git submodule update
In server directory, edit the build.rs
file according to your proto folder:
- Change
&["/home/ahmet/Documents/RustProtobufNetworking/protobuf]"
to directory where you cloned the .proto files
In server directory run
cargo build
to build the server program.
Program is generated as target/debug/server
.
In client directory, edit the build.rs
file according to your proto folder:
- Change
&["/home/ahmet/Documents/RustProtobufNetworking/protobuf]"
to directory where you cloned the .proto files
In client directory run
cargo build
to build the server program.
Program is generated as target/debug/client
.
Rust program and its libraries are fully cross-compilable. To cross compile:
- Set up cross-compiler
In .cargo/config.toml change thelinker
argument according to your toolchain. - Install target platform directives for rust using rustup
- Build
Build the server program using:
cargo build --target=<your-target-platform>
To see supported target platforms check out rustc Platform Support.
- Install a toolchain (Tested with GNU Arm Toolchain)
- Install the
armv7-unknown-linux-gnueabihf
target for rust using:
rustup target add armv7-unknown-linux-gnueabihf
- Configure the .cargo/config.toml for your toolchain
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
rustflags = ["-C", "target-feature=+crt-static"]
- Build the program with
cargo build --target=armv7-unknown-linux-gnueabihf
- Launch the server using
cargo run
command in server directory
2. Start the client using
cargo run <ip_address> <port>
If you are running the program on the same device, use 127.0.0.1 as IP address.
The hardcoded port is 2001 for server.
After starting the client; if it connects successfully it will show a prompt _>
. You can use commands:
- led on: Enable LEDs
- led off: Disable LEDs
- info: Get server IP and Port
- file <file_name>: Request a file. If file exists in file_storage/ folder in the same directory as executable