github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/playground/net.go (about) 1 // +build OMIT 2 3 package main 4 5 import ( 6 "io" 7 "log" 8 "net" 9 "os" 10 ) 11 12 func main() { 13 l, err := net.Listen("tcp", "127.0.0.1:4000") 14 if err != nil { 15 log.Fatal(err) 16 } 17 defer l.Close() 18 19 go dial() 20 21 c, err := l.Accept() 22 if err != nil { 23 log.Fatal(err) 24 } 25 defer c.Close() 26 27 io.Copy(os.Stdout, c) 28 } 29 30 func dial() { 31 c, err := net.Dial("tcp", "127.0.0.1:4000") 32 if err != nil { 33 log.Fatal(err) 34 } 35 defer c.Close() 36 c.Write([]byte("Hello, network\n")) 37 }