January 2019
Intermediate to advanced
520 pages
14h 32m
English
The first thing we need is an address. A socket address consists of an IP address and a port number. We'll use IPv4 in this book because it's widely supported. In Chapter 6, Reactive Microservices – Increasing Capacity and Performance, where we'll discuss scaling and the intercommunication of microservices, I'll show a few examples using IPv6.
The standard Rust library contains an IpAddr type to represent the IP address. We'll use the SocketAddr struct, which contains both the IpAddr and the u16 for the port number. We can construct the SocketAddr from a tuple of the ([u8; 4], u16) type. Add the following code to our main function:
let addr = ([127, 0, 0, 1], 8080).into();
We used an implementation of the impl<I: Into<IpAddr>> ...
Read now
Unlock full access