Sitemap

Member-only story

Building a custom protocol over TCP with Rust and Tokio

14 min readJun 3, 2024

Introduction

Certain applications can have specific requirements regarding network communication that make HTTP, or other existing high-level protocols, unsuitable options. This article goes over the process of building a custom protocol on top of TCP for client-server communication.

By the end of it, you should have a better understanding of how a custom protocol over TCP works and what its building blocks are, as well as feel more comfortable with building such a project yourself.

All the code written in this article can be found in the associated GitHub repository. You can refer to it if you have difficulties with any of the code.

Prerequisites

This article supposes that you have some prior knowledge of Rust — working with modules, structs, slices, and async. If you do not, it is a good idea to look into the Rust book before proceeding with this guide.

The only thing that you need to have installed on your system is Rust (and Cargo, which comes by default if you install it with rustup). You can follow the official installation guide and check that everything works as intended by running:

rustc -V
cargo -

Finally, you can create a new project by running:

cargo new rust-tcp

How does TCP work?

--

--

No responses yet