diff options
author | Andrew Gerrand <adg@golang.org> | 2013-12-13 09:27:07 +1100 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2013-12-13 09:27:07 +1100 |
commit | c7a7ecad260d219c1b693f8d76238a36ba514d71 (patch) | |
tree | 7c686d10d4297bcbf05676fcdcd8e38a38e18f76 /content/playground/net.go | |
parent | d67810e6e4ff1c7bcde714ff7267f9f0006e06eb (diff) |
go.blog: add "Inside the Go Playground" article
R=r, rsc, dsymonds
https://golang.org/cl/39180043
Diffstat (limited to 'content/playground/net.go')
-rw-r--r-- | content/playground/net.go | 35 |
1 files changed, 35 insertions, 0 deletions
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")) +} |