diff --git a/chat-tests/go.mod b/chat-tests/go.mod new file mode 100644 index 0000000..b2c6881 --- /dev/null +++ b/chat-tests/go.mod @@ -0,0 +1,3 @@ +module chat-tests + +go 1.22.2 diff --git a/chat-tests/main.go b/chat-tests/main.go new file mode 100644 index 0000000..040ead8 --- /dev/null +++ b/chat-tests/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "log" + "net" +) + +const ( + port string = "1302" +) + +func main() { + ln, err := net.Listen("tcp", ":"+port) + checkErr(err) + fmt.Printf("Listening on port %v...\n", port) + for { + conn, err := ln.Accept() + checkErr(err) + go handleFunc(conn) + } +} + +func handleFunc(conn net.Conn) { + fmt.Println("Received connection") + fmt.Fprintln(conn, "Hello buddy!") +} + +func checkErr(err error) { + if err != nil { + log.Fatalf("Error: %v\n", err) + } +}