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")
	}
}

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()
	}
}

Use log package instead of println
Use log package instead of println

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