From 5ad18b9027ea218bd69310bab8949752e44382cf Mon Sep 17 00:00:00 2001 From: Abdulmujeeb Raji Date: Tue, 18 Jul 2023 11:58:48 +0100 Subject: [PATCH] chore: initialise backend This won't be touched until a basic player prototype is implemented. The backend itself is implemented in Go. --- backend/go.mod | 3 +++ backend/main.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 backend/go.mod create mode 100644 backend/main.go diff --git a/backend/go.mod b/backend/go.mod new file mode 100644 index 0000000..fc5e5fc --- /dev/null +++ b/backend/go.mod @@ -0,0 +1,3 @@ +module github.com/devraza/ambition/backend + +go 1.20 diff --git a/backend/main.go b/backend/main.go new file mode 100644 index 0000000..78e2457 --- /dev/null +++ b/backend/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "log" + "net" + "os" +) + +const ( + serverAddress = "localhost:7764" +) + +func main() { + log.Println("Ambition going strong at", serverAddress) + + listener, err := net.Listen("tcp", serverAddress) + if err != nil { + log.Fatalln("Failed to initialise TCP listener", err) + } + defer listener.close() + + for { + conn, err := listener.Accept() + if err != nil { + log.Println("Failed to accept connection:", err) + continue + } + + // Concurrency FTW + go handleConnection(conn) + } +} + +func handleConnection(conn net.Conn) { + defer conn.Close() + + // TODO implement actual server. Waiting on frontend for this +}