In the chapter Connect the Network, the client side of the TCP connection is presented. In this recipe, the server side will be described.
Creating the TCP server
How to do it...
- Open the console and create the folder chapter09/recipe01.
- Navigate to the directory.
- Create the servertcp.go file with the following content:
package main
import (
"bufio"
"fmt"
"io"
"net"
)
func main() {
l, err := net.Listen("tcp", ":8080")
if err != nil {
panic(err)
}
for {
fmt.Println("Waiting for client...")
conn, err := l.Accept()
...