13. Network Access
When C was created, computers were rare and expensive. It was still fairly common for a company to have a single computer. Now, a computer that isn’t connected to a network is considered an oddity.
Being able to interact with the network is important for most programs. Go has a variety of packages in the standard library for network access, which is hardly surprising when you consider that Google is the language’s main backer.
Connecting to Servers
6 func tryConnect(network, host string, port int) net.Conn { 7 p := strconv.Itoa(port) 8 addr := net.JoinHostPort(host, p) 9 c, e := net.Dial(network, addr)10 if e == nil { return c }11 return nil12 }
From: connect.go
If you ...
Get The Go Programming Language Phrasebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.