Reader small image

You're reading from  Practical System Programming for Rust Developers

Product typeBook
Published inDec 2020
PublisherPackt
ISBN-139781800560963
Edition1st Edition
Tools
Right arrow
Author (1)
Prabhu Eshwarla
Prabhu Eshwarla
author image
Prabhu Eshwarla

Prabhu Eshwarla has been shipping high-quality, business-critical software to large enterprises and running IT operations for over 25 years. He is also a passionate teacher of complex technologies. Prabhu has worked with Hewlett Packard and has deep experience in software engineering, engineering management, and IT operations. Prabhu is passionate about Rust and blockchain and specializes in distributed systems. He considers coding to be a creative craft, and an excellent tool to create new digital worlds (and experiences) sustained through rigorous software engineering.
Read more about Prabhu Eshwarla

Right arrow

Programming with TCP and UDP in Rust

As discussed earlier, TCP and UDP are the fundamental transport layer network protocols for the internet. In this section, let's first write a UDP server and client. Then we'll look at doing the same using TCP.

Create a new project called tcpudp where we will write the TCP and UDP servers and clients:

cargo new tcpudp && cd tcpudp

Let's first look at network communication using UDP.

Writing a UDP server and client

In this section, we'll learn how to configure UDP sockets, and how to send and receive data. We'll write both a UDP server and a UDP client.

Starting with the UDP server

In the example shown, we're creating a UDP server by binding to a local socket using UdpSocket::bind. We're then creating a fixed-size buffer, and listening for incoming data streams in a loop. If data is received, we are spawning a new thread to process the data by echoing it back to the sender. As we already...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical System Programming for Rust Developers
Published in: Dec 2020Publisher: PacktISBN-13: 9781800560963

Author (1)

author image
Prabhu Eshwarla

Prabhu Eshwarla has been shipping high-quality, business-critical software to large enterprises and running IT operations for over 25 years. He is also a passionate teacher of complex technologies. Prabhu has worked with Hewlett Packard and has deep experience in software engineering, engineering management, and IT operations. Prabhu is passionate about Rust and blockchain and specializes in distributed systems. He considers coding to be a creative craft, and an excellent tool to create new digital worlds (and experiences) sustained through rigorous software engineering.
Read more about Prabhu Eshwarla