From cc935e2535ff65dfe88ddaa43dded7816179ee49 Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 27 Jun 2019 01:10:33 +0200 Subject: updated the service: now printing what it recieves --- example-service/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'example-service/main.go') diff --git a/example-service/main.go b/example-service/main.go index bbdc35f..f32c273 100644 --- a/example-service/main.go +++ b/example-service/main.go @@ -8,13 +8,12 @@ import ( ) const( - CONN_HOST = "localhost" + CONN_HOST = "127.0.0.1" CONN_PORT = "3333" CONN_TYPE = "tcp" ) func main() { - // start a new listener l, err := net.Listen(CONN_TYPE, CONN_HOST + ":" + CONN_PORT) if err != nil { @@ -26,23 +25,22 @@ func main() { defer l.Close() for { - // accept a connection conn, err := l.Accept() + if err != nil { log.Printf("Error accepting: %v", err) os.Exit(1) } // handle the connection in a new go thread - go handlerequest(conn) - + handlerequest(conn) } } func handlerequest(conn net.Conn) { // creat a buffer storing the incomming data - buf := make([]byte, 1000) + buf := make([]byte, 10000) // read from the connection into the buffer reqLen, err := conn.Read(buf) @@ -51,6 +49,8 @@ func handlerequest(conn net.Conn) { os.Exit(1) } + fmt.Println(string(buf)) + // write back how many bytes were sent conn.Write([]byte(fmt.Sprintf("Read %d bytes", reqLen))) conn.Close() -- cgit 1.4.1