package main

import(
	"log"
	"net"
)

const(
	RECV_BUF_LEN = 1024
)

func main() {
	log.Print("Starting the server")
	listener, err := net.Listen("tcp", "127.0.0.1:8377")
	if err != nil {
		log.Fatal("Listen: ", err.Error())
	}

	for {
		conn, err := listener.Accept()
		if err != nil {
			log.Print("Accept: ", err.Error())
			return
		}

		go HandleConnection(conn)
	}
}

func HandleConnection(conn net.Conn) {
	buf := make([]byte, RECV_BUF_LEN)
	n, err := conn.Read(buf)
	if err != nil {
		log.Print("Read: ", err.Error())
		return
	}

	log.Print("Received ", n, " bytes of data")
	_, err = conn.Write(buf)
	if err != nil {
		log.Print("Write: ", err.Error())
		return
	} else {
		log.Print("Reply echoed")
		conn.Close()
	}
}

package main

import(
	"net"
	"os"
)

const(
	RECV_BUF_LEN = 1024
)

func main() {
	println("Starting the server")
	listener, err := net.Listen("tcp", "127.0.0.1:8377")
	if err != nil {
		println("error Listen: ", err.Error())
		os.Exit(1)
	}

	for {
		conn, err := listener.Accept()
		if err != nil {
			println("error Accept: ", err.Error())
			return
		}

		go HandleConnection(conn)
	}
}

func HandleConnection(conn net.Conn) {
	buf := make([]byte, RECV_BUF_LEN)
	n, err := conn.Read(buf)
	if err != nil {
		println("error Read: ", err.Error())
		return
	}
	println("Received ", n, " bytes of data: ", string(buf))
	_, err = conn.Write(buf)
	if err != nil {
		println("error Write: ", err.Error())
		return
	} else {
		println("Reply echoed")
	}
}

--- 
+++ 
@@ -1,8 +1,8 @@
 package main
 
 import(
+	"log"
 	"net"
-	"os"
 )
 
 const(
@@ -10,17 +10,16 @@
 )
 
 func main() {
-	println("Starting the server")
+	log.Print("Starting the server")
 	listener, err := net.Listen("tcp", "127.0.0.1:8377")
 	if err != nil {
-		println("error Listen: ", err.Error())
-		os.Exit(1)
+		log.Fatal("Listen: ", err.Error())
 	}
 
 	for {
 		conn, err := listener.Accept()
 		if err != nil {
-			println("error Accept: ", err.Error())
+			log.Print("Accept: ", err.Error())
 			return
 		}
 
@@ -32,15 +31,17 @@
 	buf := make([]byte, RECV_BUF_LEN)
 	n, err := conn.Read(buf)
 	if err != nil {
-		println("error Read: ", err.Error())
+		log.Print("Read: ", err.Error())
 		return
 	}
-	println("Received ", n, " bytes of data: ", string(buf))
+
+	log.Print("Received ", n, " bytes of data")
 	_, err = conn.Write(buf)
 	if err != nil {
-		println("error Write: ", err.Error())
+		log.Print("Write: ", err.Error())
 		return
 	} else {
-		println("Reply echoed")
+		log.Print("Reply echoed")
+		conn.Close()
 	}
 }
Use log package instead of println

Signed-off-by: Wincent Colaiuta <c76ac2e9cd86441713c7dfae92c451f3e6d17fdc@wincent.com>
