You are previewing The Go Programming Language Phrasebook.

The Go Programming Language Phrasebook

Cover of The Go Programming Language Phrasebook by David Chisnall Published by Addison-Wesley Professional

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

The best content for your career. Discover unlimited learning on demand for around $1/day.