October 2015
Beginner to intermediate
400 pages
14h 44m
English
The clock server used one goroutine per connection.
In this section, we’ll build an echo server that uses multiple
goroutines per connection.
Most echo servers merely write whatever they read, which can be
done with this trivial version of handleConn:
func handleConn(c net.Conn) {
io.Copy(c, c) // NOTE: ignoring errors
c.Close()
}
A more interesting echo server might simulate the reverberations
of a real echo, with the
response loud at first ("HELLO!"), then moderate
("Hello!") after a delay, then quiet ("hello!") before
fading to nothing, as in this version of handleConn:
func echo(c net.Conn, shout string, delay time.Duration) ...