aboutsummaryrefslogtreecommitdiff
path: root/content/playground/net.go
diff options
context:
space:
mode:
Diffstat (limited to 'content/playground/net.go')
-rw-r--r--content/playground/net.go35
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"))
+}