O'Reilly logo

The Go Programming Language Phrasebook by David Chisnall

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

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

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