From 6a53f6c2b948ef5679e7d97f59747439e93361b4 Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 29 Jun 2018 16:27:39 -0700 Subject: [PATCH] first commit for loghost --- aws-code/loghost/main.go | 53 ++++++++++++++++++++++++++++++++++++++++ benchmark_main.go | 3 ++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 aws-code/loghost/main.go diff --git a/aws-code/loghost/main.go b/aws-code/loghost/main.go new file mode 100644 index 000000000..2f6a4f46c --- /dev/null +++ b/aws-code/loghost/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "bufio" + "fmt" + "net" + "os" +) + +const ( + CONN_PORT = "3000" + CONN_TYPE = "tcp" +) + +func main() { + // Listen for incoming connections. + l, err := net.Listen(CONN_TYPE, ":"+CONN_PORT) + if err != nil { + fmt.Println("Error listening:", err.Error()) + os.Exit(1) + } + // Close the listener when the application closes. + defer l.Close() + fmt.Println("Listening on " + ":" + CONN_PORT) + for { + // Listen for an incoming connection. + conn, err := l.Accept() + if err != nil { + fmt.Println("Error accepting: ", err.Error()) + os.Exit(1) + } + // Handle connections in a new goroutine. + go handleRequest(conn) + } +} + +// Handles incoming requests. +func handleRequest(conn net.Conn) { + // // Make a buffer to hold incoming data. + // buf := make([]byte, 1024) + // // Read the incoming connection into the buffer. + // reqLen, err := conn.Read(buf) + status, err := bufio.NewReader(conn).ReadString('\n') + if err != nil { + fmt.Println("Error reading:", err.Error()) + } + // fmt.Printf("Received %v: %v", reqLen, buf) + fmt.Println(status) + // // Send a response back to person contacting xus. + // conn.Write([]byte("Message received.")) + // Close the connection when you're done with it. + conn.Close() +} diff --git a/benchmark_main.go b/benchmark_main.go index eb8ff2578..9ecfdba3f 100644 --- a/benchmark_main.go +++ b/benchmark_main.go @@ -87,7 +87,8 @@ func main() { logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port) h := log.MultiHandler( log.Must.FileHandler(logFileName, log.LogfmtFormat()), - log.StdoutHandler) + log.StdoutHandler, + log.Must.NetHandler("tcp", ":3000", log.JSONFormat())) // In cases where you just want a stdout logger, use the following one instead. // h := log.CallerFileHandler(log.StdoutHandler) log.Root().SetHandler(h)