From 35d636cdc24a5da1a120d5e9432de023983c6d01 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Fri, 1 Jul 2022 02:55:31 -0500 Subject: [PATCH] stuff --- go.mod | 3 +++ server/main.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 go.mod create mode 100644 server/main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..de83f84 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/vilmibm/hermeticum + +go 1.18 diff --git a/server/main.go b/server/main.go new file mode 100644 index 0000000..9c31d1d --- /dev/null +++ b/server/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + "net" + "os" +) + +func _main() (err error) { + var listener net.Listener + listener, err = net.Listen("tcp", "127.0.0.1:6666") + if err != nil { + return + } + + defer listener.Close() + + for { + var conn net.Conn + conn, err = listener.Accept() + if err != nil { + // TODO log and continue + break + } + + go handleConnection(conn) + } + + return +} + +func handleConnection(conn net.Conn) { + // TODO create a user session + fmt.Println("HI") + + // TODO learn how to read from here -> protobuff + for { + var bs []byte + // TODO how to block here? + conn.Read(bs) + fmt.Printf("DBG %#v\n", string(bs)) + } +} + +func main() { + fmt.Println("hi lol") + err := _main() + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } +}