October 2015
Beginner to intermediate
400 pages
14h 44m
English
We’ll finish this chapter with a chat server that lets several
users broadcast textual messages to each other.
There are four kinds of goroutine in this program.
There is one instance apiece of the main and broadcaster
goroutines, and for each client connection there is one
handleConn and one clientWriter goroutine.
The broadcaster is a good illustration of how select is used,
since it has to respond to three different kinds of messages.
The job of the main goroutine, shown below, is to listen for and
accept incoming network connections from clients.
For each one, it creates a new handleConn goroutine, just as
in the concurrent echo server we saw at the start of this chapter.