Commits

Miki Tebeka committed 7b6102a

echo

Comments (0)

Files changed (2)

 *.out
 avg64
 cat
+echo
 fact
 fib
 fizzbuzz
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"net"
+	"os"
+)
+
+func handle(conn net.Conn) {
+	defer conn.Close()
+
+	reader := bufio.NewReader(conn)
+	message, err := reader.ReadBytes('\n')
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "error: can't read (%s)\n", err)
+		return
+	}
+	conn.Write([]byte(message))
+}
+
+func main() {
+	listener, err := net.Listen("tcp", ":8053")
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "error: can't listen (%s)\n", err)
+		os.Exit(1)
+	}
+
+	defer listener.Close()
+
+	for {
+		conn, err := listener.Accept()
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "error: can't accept (%s)\n", err)
+			os.Exit(1)
+		}
+		go handle(conn)
+	}
+}
+