O'Reilly logo

Network Programming with Rust by Abhishek Chanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing streaming protocols

In a number of cases, a protocol has a data unit with a header attached to it. The server typically reads the header first and, based on that, decides how to process the data. In some cases, the server may be able to do some processing based on the header. One such example is IP, which has a header that has the destination address. A server may start running a longest prefix match based on that information, before reading the body. In this section, we will look into using tokio to write such servers. We will expand our toy collatz protocol to include a header and some data body, and work from there. Let us start with an example, and our project setup will be exactly the same, setting it up using Cargo:

$ cargo ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required