O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

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

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 ...

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