Network Programming with Rust

Book description

Learn to write servers and network clients using Rust's low-level socket classes with this guide

About This Book

  • Build a solid foundation in Rust while also mastering important network programming details
  • Leverage the power of a number of available libraries to perform network operations in Rust
  • Develop a fully functional web server to gain the skills you need, fast

Who This Book Is For

This book is for software developers who want to write networking software with Rust. A basic familiarity with networking concepts is assumed. Beginner-level knowledge of Rust will help but is not necessary.

What You Will Learn

  • Appreciate why networking is important in implementing distributed systems
  • Write a non-asynchronous echo server over TCP that talks to a client over a network
  • Parse JSON and binary data using parser combinators such as nom
  • Write an HTTP client that talks to the server using reqwest
  • Modify an existing Rust HTTTP server and add SSL to it
  • Master asynchronous programming support in Rust
  • Use external packages in a Rust project

In Detail

Rust is low-level enough to provide fine-grained control over memory while providing safety through compile-time validation. This makes it uniquely suitable for writing low-level networking applications.

This book is divided into three main parts that will take you on an exciting journey of building a fully functional web server. The book starts with a solid introduction to Rust and essential networking concepts. This will lay a foundation for, and set the tone of, the entire book. In the second part, we will take an in-depth look at using Rust for networking software. From client-server networking using sockets to IPv4/v6, DNS, TCP, UDP, you will also learn about serializing and deserializing data using serde. The book shows how to communicate with REST servers over HTTP. The final part of the book discusses asynchronous network programming using the Tokio stack. Given the importance of security for modern systems, you will see how Rust supports common primitives such as TLS and public-key cryptography.

After reading this book, you will be more than confident enough to use Rust to build effective networking software

Style and approach

This book will get you started with building networking software in Rust by taking you through all the essential concepts.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Network Programming with Rust
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  7. Introduction to Client/Server Networking
    1. A brief history of networks
    2. Layering in networks
    3. Addressing in networks
    4. How IP routing works
    5. How DNS works
    6. Common service models
      1. Connection-oriented service
      2. Connectionless service
    7. The network programming interface in Linux
    8. Summary
  8. Introduction to Rust and its Ecosystem
    1. The Rust ecosystem
    2. Getting started with Rust
    3. Introduction to the borrow checker
    4. Generics and the trait system
    5. Error handling
    6. The macro system
      1. Syntactic macros
      2. Procedural macros
    7. Functional features in Rust
      1. Higher-order functions
      2. Iterators
    8. Concurrency primitives
    9. Testing
    10. Summary
  9. TCP and UDP Using Rust
    1. A Simple TCP server and client
    2. A Simple UDP server and client
      1. UDP multicasting
    3. Miscellaneous utilities in std::net
    4. Some related crates
    5. Summary
  10. Data Serialization, Deserialization, and Parsing
    1. Serialization and deserialization using Serde
      1. Custom serialization and deserialization
    2. Parsing textual data
    3. Parsing binary data
    4. Summary
  11. Application Layer Protocols
    1. Introduction to RPC
    2. Introduction to SMTP
    3. Introduction to FTP and TFTP
    4. Summary
  12. Talking HTTP in the Internet
    1. Introducing Hyper
    2. Introducing Rocket
    3. Introducing reqwest
    4. Summary
  13. Asynchronous Network Programming Using Tokio
    1. Looking into the Future
      1. Working with streams and sinks
    2. Heading to tokio
      1. Socket multiplexing in tokio
      2. Writing streaming protocols
      3. The larger tokio ecosystem
    3. Conclusion
  14. Security
    1. Securing the web
      1. Letsencrypt using Rust
      2. OpenSSL using Rust
      3. Securing tokio applications
    2. Cryptography using ring
    3. Summary
  15. Appendix
    1. Introduction to coroutines and generators
      1. How May handles coroutines
    2. Awaiting the future
    3. Data parallelism
    4. Parsing using Pest
    5. Miscellaneous utilities
    6. Summary
  16. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Network Programming with Rust
  • Author(s): Abhishek Chanda
  • Release date: February 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788624893