7 File access and basic networking
This chapter covers
- Handling the manipulation of files locally or on a network
- Networking with Transmission Control Protocol (TCP) and User Datagram Protocol (UDP)
- Applying basic bidirectional networking to a web chat app using websockets
- Using unidirectional networking to send messages from a server to a persistent client connection
Go was initially designed as a systems language but quickly became more general-purpose prior to the first release. By that point, its concurrency focus put it in a unique position in the language landscape and made it especially viable and popular for servers and networking. In this chapter and chapters 8 through 11, we’ll cover how Go fits in the web landscape, including some niche use cases.
In chapter 6, we worked with log files, which let us touch the filesystem a little bit via a proxy in Go’s log package. But we didn’t look too deeply into the file access methods that Go uses under the hood to create, read, and manipulate files.
Some of the prerequisites for this include being able to open and use data from our filesystem. We’ll look at opening, reading, and writing to files. Next, we’ll go a little low-level by working with UDP and TCP connections outside the standard library net/http
package. Finally, we’ll build some small web applications that work with persistent network connections to provide more real-time functionality.