about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-06-27 01:10:33 +0200
committerEmile <hanemile@protonmail.com>2019-06-27 01:10:33 +0200
commitcc935e2535ff65dfe88ddaa43dded7816179ee49 (patch)
treef35e3be35c5c6ecad5bef37cbc433b50b6e795e8
parent6ab0a595e7613d285b524f5643e828373f881fb4 (diff)
updated the service: now printing what it recieves
-rw-r--r--example-service/Dockerfile10
-rw-r--r--example-service/main.go12
2 files changed, 6 insertions, 16 deletions
diff --git a/example-service/Dockerfile b/example-service/Dockerfile
deleted file mode 100644
index 8fa6104..0000000
--- a/example-service/Dockerfile
+++ /dev/null
@@ -1,10 +0,0 @@
-FROM golang:latest
-
-WORKDIR /home
-COPY *.go /home/
-
-RUN go get github.com/gorilla/mux
-
-EXPOSE 3333
-
-ENTRYPOINT go run .
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()