From c7a7ecad260d219c1b693f8d76238a36ba514d71 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Fri, 13 Dec 2013 09:27:07 +1100 Subject: go.blog: add "Inside the Go Playground" article R=r, rsc, dsymonds https://golang.org/cl/39180043 --- content/playground/net.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 content/playground/net.go (limited to 'content/playground/net.go') diff --git a/content/playground/net.go b/content/playground/net.go new file mode 100644 index 0000000..2728055 --- /dev/null +++ b/content/playground/net.go @@ -0,0 +1,35 @@ +package main + +import ( + "io" + "log" + "net" + "os" +) + +func main() { + l, err := net.Listen("tcp", "127.0.0.1:4000") + if err != nil { + log.Fatal(err) + } + defer l.Close() + + go dial() + + c, err := l.Accept() + if err != nil { + log.Fatal(err) + } + defer c.Close() + + io.Copy(os.Stdout, c) +} + +func dial() { + c, err := net.Dial("tcp", "127.0.0.1:4000") + if err != nil { + log.Fatal(err) + } + defer c.Close() + c.Write([]byte("Hello, network\n")) +} -- cgit v1.2.3