How it works...
The net package contains the Dial function, which consumes the network type and address. In the previous example, the network is tcp and the address is localhost:8080.
Once the Dial function is successful, the Conn type is returned, which serves as a reference to the opened socket. The Conn interface also defines the Read and Write functions, so they can be used as Writer and Reader functions for writing and reading from the socket. Finally, the sample code uses Scanner to obtain the response. Note that the Scanner, in this case, works because of the brake lines. Otherwise, the more generic Read method should be used. In the example, the Read deadline is set via the SetReadDeadline method. The important thing about this is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access